結果

問題 No.1374 Absolute Game
コンテスト
ユーザー face4
提出日時 2021-07-24 11:52:36
言語 Kotlin
(2.3.20)
コンパイル:
kotlinc _filename_ -include-runtime -d main.jar
実行:
kotlin main.jar
結果
AC  
実行時間 450 ms / 2,000 ms
+ 195µs
コード長 375 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,742 ms
コンパイル使用メモリ 514,948 KB
実行使用メモリ 77,364 KB
最終ジャッジ日時 2026-08-18 19:22:08
合計ジャッジ時間 19,599 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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