29 lines
911 B
Kotlin
Executable File
29 lines
911 B
Kotlin
Executable File
#!/usr/bin/env kotlin
|
|
import java.io.File
|
|
import java.util.Scanner
|
|
import kotlin.math.abs
|
|
|
|
val scanner = Scanner(System.`in`)
|
|
val firstList = mutableListOf<Int>()
|
|
val secondList = mutableListOf<Int>()
|
|
var secondMap = mutableMapOf<Int, Int>()
|
|
while (scanner.hasNextLine()) {
|
|
val line = scanner.nextLine()
|
|
val numbers = line.split(" ")
|
|
val firstNumber = numbers[0].toInt()
|
|
val secondNumber = numbers[1].toInt()
|
|
firstList.add(firstNumber)
|
|
secondList.add(secondNumber)
|
|
secondMap[secondNumber] = (secondMap[secondNumber] ?: 0) + 1
|
|
}
|
|
firstList.sort()
|
|
secondList.sort()
|
|
var totaldistance = 0
|
|
var similarityscore = 0
|
|
for (i in firstList.indices) {
|
|
val distance = abs(firstList[i] - secondList[i])
|
|
totaldistance += distance
|
|
similarityscore += (secondMap[firstList[i]] ?: 0) * firstList[i]
|
|
}
|
|
println("Total distance: $totaldistance")
|
|
println("Similarity score: $similarityscore") |