結果

問題 No.1374 Absolute Game
コンテスト
ユーザー face4
提出日時 2021-07-24 11:52:36
言語 Kotlin
(2.4.21 + ACL)
コンパイル:
kotlinc -cp /opt/aclib/ac_library.jar _filename_ -include-runtime -d main.jar
実行:
java -cp main.jar:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 433 ms / 2,000 ms
+ 460µs
コード長 375 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,667 ms
コンパイル使用メモリ 538,184 KB
実行使用メモリ 70,592 KB
最終ジャッジ日時 2026-10-16 11:51:37
合計ジャッジ時間 19,803 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import kotlin.math.abs

// editorial
fun main() {
    val n = readLine()!!.toInt()
    var a = readLine()!!.split(" ").map { it.toLong() }
    if (a.sum() < 0) {
        a = a.map { -it }
    }
    a = a.sortedDescending()
    var (x, y) = listOf(0L, 0L)
    for (i in a.indices) {
        if (i % 2 == 0) x += a[i]
        else y += a[i]
    }
    println(abs(x) - abs(y))
}
0