23 lines
434 B
Text
23 lines
434 B
Text
|
import java.util.Scanner
|
||
|
import kotlin.math.abs
|
||
|
|
||
|
val scanner = Scanner(System.`in`)
|
||
|
|
||
|
val listLeft = ArrayList<Int>()
|
||
|
val listRight = ArrayList<Int>()
|
||
|
|
||
|
while (scanner.hasNextInt()) {
|
||
|
val num1 = scanner.nextInt()
|
||
|
listLeft.add(num1)
|
||
|
|
||
|
val num2 = scanner.nextInt()
|
||
|
listRight.add(num2)
|
||
|
}
|
||
|
|
||
|
val pairs = listLeft.sorted() zip listRight.sorted()
|
||
|
|
||
|
val result = pairs.fold(0) { acc, (l, r) -> acc + abs(l - r) }
|
||
|
|
||
|
println(result)
|
||
|
|