結果

問題 No.1906 Twinkle Town
ユーザー donutholedonuthole
提出日時 2022-12-24 15:44:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 1,835 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 111,756 KB
最終ジャッジ日時 2024-04-29 04:54:17
合計ジャッジ時間 20,531 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 166 ms
83,200 KB
testcase_01 AC 167 ms
83,328 KB
testcase_02 AC 170 ms
82,944 KB
testcase_03 AC 356 ms
84,352 KB
testcase_04 AC 340 ms
84,480 KB
testcase_05 AC 357 ms
84,608 KB
testcase_06 AC 333 ms
84,480 KB
testcase_07 AC 362 ms
84,608 KB
testcase_08 AC 356 ms
84,736 KB
testcase_09 AC 346 ms
84,480 KB
testcase_10 AC 348 ms
84,608 KB
testcase_11 AC 352 ms
84,608 KB
testcase_12 AC 337 ms
84,480 KB
testcase_13 AC 355 ms
84,864 KB
testcase_14 AC 344 ms
84,608 KB
testcase_15 AC 358 ms
84,352 KB
testcase_16 AC 326 ms
84,480 KB
testcase_17 AC 337 ms
84,352 KB
testcase_18 AC 335 ms
84,736 KB
testcase_19 AC 339 ms
84,352 KB
testcase_20 AC 329 ms
84,352 KB
testcase_21 AC 318 ms
84,096 KB
testcase_22 AC 284 ms
84,224 KB
testcase_23 AC 313 ms
84,224 KB
testcase_24 AC 286 ms
84,224 KB
testcase_25 AC 311 ms
84,224 KB
testcase_26 AC 299 ms
83,968 KB
testcase_27 AC 319 ms
84,096 KB
testcase_28 AC 298 ms
84,224 KB
testcase_29 AC 334 ms
98,816 KB
testcase_30 AC 328 ms
101,504 KB
testcase_31 AC 340 ms
99,696 KB
testcase_32 AC 309 ms
93,184 KB
testcase_33 AC 334 ms
99,200 KB
testcase_34 AC 314 ms
102,912 KB
testcase_35 AC 343 ms
100,148 KB
testcase_36 AC 315 ms
98,656 KB
testcase_37 AC 355 ms
106,040 KB
testcase_38 AC 310 ms
96,896 KB
testcase_39 AC 351 ms
111,516 KB
testcase_40 AC 356 ms
111,376 KB
testcase_41 AC 359 ms
111,220 KB
testcase_42 AC 358 ms
111,756 KB
testcase_43 AC 354 ms
111,524 KB
testcase_44 AC 347 ms
111,520 KB
testcase_45 AC 304 ms
84,352 KB
testcase_46 AC 336 ms
84,480 KB
testcase_47 AC 328 ms
84,480 KB
testcase_48 AC 314 ms
84,480 KB
testcase_49 AC 301 ms
83,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# region template

from platform import node
from typing import Generic, Iterable, Iterator, TypeVar, Union, List
from bisect import bisect_left, bisect_right, insort
from re import A
import typing
import math
import sys
import copy
import itertools
import collections
import bisect
import heapq
import decimal


def ni(): return int(sys.stdin.readline())
def ns(): return map(int, sys.stdin.readline().split())
def ns1(): return map(lambda x: int(x)-1, sys.stdin.readline().split())
def na(): return list(map(int, sys.stdin.readline().split()))
def na1(): return list(map(lambda x: int(x)-1, sys.stdin.readline().split()))
def nall_i(): return list(map(int, sys.stdin.read().split()))
def nall_s(): return list(map(str, sys.stdin.read().split()))
def flush(): return sys.stdout.flush()
def nib(): return int(sys.stdin.buffer.readline())
def nsb(): return map(int, sys.stdin.buffer.readline().split())
def ns1b(): return map(lambda x: int(x)-1, sys.stdin.buffer.readline().split())
def nab(): return list(map(int, sys.stdin.buffer.readline().split()))
def na1b(): return list(map(lambda x: int(x)-1, sys.stdin.buffer.readline().split()))
def nallb(): return list(map(int, sys.stdin.buffer.read().split()))
# limregion


# sys.setrecursionlimit(10**7+1)
inf = 10**23
# mod = 10**9+7
mod = 998244353


def main():
    # https://open.spotify.com/track/6ldZaRUFcKh908SJXwdbZj?si=383824f68a8a47c0
    def solve():
        N = ni()
        A = na()
        A.sort()

        B = [A[0] if i == 0 else A[i]-A[i-1] for i in range(N)]

        hq = []
        res = 0
        for i, bi in enumerate(B):
            heapq.heappush(hq, -bi)
            if i % 2 == 0:
                res += -heapq.heappop(hq)

        print(res if N % 2 else A[-1]-res)

    T = ni()
    for _ in range(T):
        solve()


if __name__ == '__main__':
    main()
0