結果

問題 No.1374 Absolute Game
ユーザー face4face4
提出日時 2021-07-24 11:52:36
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 737 ms / 2,000 ms
コード長 375 bytes
コンパイル時間 16,138 ms
コンパイル使用メモリ 426,856 KB
実行使用メモリ 71,848 KB
最終ジャッジ日時 2023-09-26 22:36:04
合計ジャッジ時間 32,064 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 317 ms
56,912 KB
testcase_01 AC 320 ms
56,960 KB
testcase_02 AC 318 ms
57,068 KB
testcase_03 AC 325 ms
56,968 KB
testcase_04 AC 325 ms
56,904 KB
testcase_05 AC 319 ms
57,332 KB
testcase_06 AC 318 ms
56,940 KB
testcase_07 AC 320 ms
56,932 KB
testcase_08 AC 567 ms
59,756 KB
testcase_09 AC 673 ms
66,024 KB
testcase_10 AC 688 ms
65,868 KB
testcase_11 AC 648 ms
62,080 KB
testcase_12 AC 577 ms
59,708 KB
testcase_13 AC 651 ms
61,540 KB
testcase_14 AC 737 ms
65,840 KB
testcase_15 AC 722 ms
70,156 KB
testcase_16 AC 725 ms
65,796 KB
testcase_17 AC 725 ms
70,272 KB
testcase_18 AC 702 ms
65,912 KB
testcase_19 AC 728 ms
71,848 KB
testcase_20 AC 571 ms
59,920 KB
testcase_21 AC 611 ms
59,764 KB
testcase_22 AC 706 ms
65,888 KB
testcase_23 AC 490 ms
59,376 KB
testcase_24 AC 526 ms
59,472 KB
testcase_25 AC 527 ms
59,488 KB
testcase_26 AC 567 ms
59,940 KB
testcase_27 AC 604 ms
59,780 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:5:9: warning: variable 'n' is never used
    val n = readLine()!!.toInt()
        ^

ソースコード

diff #

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