2024-12-03 07:26:53 +00:00
|
|
|
#!/usr/bin/env kotlin
|
2024-12-02 13:06:26 +00:00
|
|
|
import java.io.File
|
|
|
|
import java.util.Scanner
|
|
|
|
import kotlin.math.abs
|
|
|
|
|
2024-12-05 13:43:19 +00:00
|
|
|
val scanner = Scanner(System.`in`)
|
2024-12-02 13:06:26 +00:00
|
|
|
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]
|
|
|
|
}
|
2024-12-02 13:06:27 +00:00
|
|
|
println("Total distance: $totaldistance")
|
|
|
|
println("Similarity score: $similarityscore")
|