結果

問題 No.1906 Twinkle Town
ユーザー 👑 hitonanodehitonanode
提出日時 2022-02-05 14:11:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 806 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 107,868 KB
最終ジャッジ日時 2023-09-04 04:33:56
合計ジャッジ時間 17,389 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,332 KB
testcase_01 AC 76 ms
71,496 KB
testcase_02 AC 76 ms
71,492 KB
testcase_03 AC 281 ms
80,872 KB
testcase_04 AC 271 ms
80,556 KB
testcase_05 AC 267 ms
79,088 KB
testcase_06 AC 267 ms
81,152 KB
testcase_07 AC 292 ms
80,356 KB
testcase_08 AC 278 ms
80,480 KB
testcase_09 AC 277 ms
80,532 KB
testcase_10 AC 282 ms
80,420 KB
testcase_11 AC 280 ms
80,856 KB
testcase_12 AC 271 ms
80,952 KB
testcase_13 AC 287 ms
80,516 KB
testcase_14 AC 260 ms
79,092 KB
testcase_15 AC 276 ms
79,488 KB
testcase_16 AC 261 ms
79,140 KB
testcase_17 AC 277 ms
81,176 KB
testcase_18 AC 274 ms
79,352 KB
testcase_19 AC 275 ms
80,788 KB
testcase_20 AC 265 ms
79,244 KB
testcase_21 AC 227 ms
78,544 KB
testcase_22 AC 194 ms
78,520 KB
testcase_23 AC 228 ms
78,680 KB
testcase_24 AC 196 ms
78,616 KB
testcase_25 AC 227 ms
79,096 KB
testcase_26 AC 206 ms
78,908 KB
testcase_27 AC 228 ms
78,056 KB
testcase_28 AC 207 ms
78,984 KB
testcase_29 AC 237 ms
95,476 KB
testcase_30 AC 226 ms
96,368 KB
testcase_31 AC 235 ms
91,784 KB
testcase_32 AC 211 ms
88,936 KB
testcase_33 AC 241 ms
94,408 KB
testcase_34 AC 217 ms
97,616 KB
testcase_35 AC 239 ms
92,492 KB
testcase_36 AC 212 ms
93,788 KB
testcase_37 AC 247 ms
103,760 KB
testcase_38 AC 215 ms
91,936 KB
testcase_39 AC 255 ms
107,396 KB
testcase_40 AC 257 ms
107,560 KB
testcase_41 AC 258 ms
107,420 KB
testcase_42 AC 257 ms
107,868 KB
testcase_43 AC 256 ms
107,092 KB
testcase_44 AC 270 ms
107,628 KB
testcase_45 AC 218 ms
79,984 KB
testcase_46 AC 244 ms
78,628 KB
testcase_47 AC 265 ms
79,056 KB
testcase_48 AC 233 ms
78,220 KB
testcase_49 AC 204 ms
78,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 想定解
# Python3 でも通る(なんならそっちの方が速い)んですが、シンプル軽実装がバレるので、PyPy にします
import heapq


def solve() -> int:
    N, A = int(input()), sorted(map(int, input().split()))

    heap = list()
    ret, latest_a = 0, 0

    for i, a in enumerate(A):
        heapq.heappush(heap, -(a - latest_a))  # 大きいものから取り出したいので符号反転させて入れる
        latest_a = a
        if i % 2 == 0:
            ret -= heapq.heappop(heap)

    return ret if N % 2 else A[-1] - ret


ret = [solve() for _ in range(int(input()))]
print(*ret, sep='\n')
0