Submission #3604328


Source Code Expand

fun c92(args: Array<String>) {
    val numList = listOf(0).plus(args[1].split(" ").map { it.toInt() }).plus(0)
    val cost = numList.zipWithNext { a, b -> Math.abs(b - a) }.sum()

    val ans = (0..numList.size - 3)
            .map {
                val before = Math.abs(numList[it + 2] - numList[it + 1]) + Math.abs(numList[it + 1] - numList[it])
                val after = Math.abs(numList[it + 2] - numList[it])
                cost - (before - after)
            }
            .joinToString("\n")

    println(ans)
}

fun main(args: Array<String>) {
    c92(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Submission Info

Submission Time
Task C - Traveling Plan
User choruru
Language Kotlin (1.0.0)
Score 0
Code Size 901 Byte
Status CE

Compile Error

Main.kt:4:24: error: unresolved reference: zipWithNext
    val cost = numList.zipWithNext { a, b -> Math.abs(b - a) }.sum()
                       ^
Main.kt:4:38: error: cannot infer a type for this parameter. Please specify it explicitly.
    val cost = numList.zipWithNext { a, b -> Math.abs(b - a) }.sum()
                                     ^
Main.kt:4:41: error: cannot infer a type for this parameter. Please specify it explicitly.
    val cost = numList.zipWithNext { a, b -> Math.abs(b - a) }.sum()
                                        ^