結果
| 問題 |
No.1374 Absolute Game
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-24 11:52:36 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 757 ms / 2,000 ms |
| コード長 | 375 bytes |
| コンパイル時間 | 15,211 ms |
| コンパイル使用メモリ | 445,140 KB |
| 実行使用メモリ | 74,732 KB |
| 最終ジャッジ日時 | 2024-07-19 16:21:48 |
| 合計ジャッジ時間 | 32,588 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 |
コンパイルメッセージ
Main.kt:5:9: warning: variable 'n' is never used
val n = readLine()!!.toInt()
^
ソースコード
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))
}