結果
問題 | No.1906 Twinkle Town |
ユーザー |
![]() |
提出日時 | 2022-12-24 15:44:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 345 ms / 2,000 ms |
コード長 | 1,835 bytes |
コンパイル時間 | 412 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 111,512 KB |
最終ジャッジ日時 | 2024-11-18 05:18:39 |
合計ジャッジ時間 | 19,739 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 47 |
ソースコード
# 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()