/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 41ms 17.926 MiB
#2 Accepted 43ms 18.023 MiB
#3 Accepted 44ms 17.863 MiB
#4 Accepted 41ms 17.871 MiB
#5 Accepted 95ms 19.492 MiB
#6 Accepted 66ms 19.242 MiB
#7 Accepted 105ms 39.367 MiB
#8 Accepted 123ms 41.703 MiB
#9 Accepted 144ms 41.883 MiB
#10 Accepted 132ms 42.98 MiB
#11 Accepted 92ms 20.543 MiB
#12 Accepted 93ms 19.605 MiB
#13 Accepted 89ms 40.668 MiB
#14 Accepted 140ms 41.266 MiB
#15 Accepted 101ms 20.457 MiB
#16 Accepted 98ms 20.633 MiB
#17 Accepted 86ms 19.207 MiB

Code

import sys
from itertools import *
from bisect import *
from collections import *
from math import gcd
import heapq

input = lambda: sys.stdin.readline().rstrip("\r\n")
rint = lambda: int(input())
rlist = lambda: list(map(int, input().split()))
rgrid = lambda n: [rlist() for _ in range(n)]

fmin = lambda x, y: x if x < y else y
fmax = lambda x, y: x if x > y else y
# MOD = 998244353
MOD = 10**9 + 7
INF = float("inf")


def solve():
    N = rint()
    A = rlist()
    A.sort(reverse=True)
    P = [0] * (N + 1)
    for i, x in enumerate(A):
        P[i + 1] = P[i] + (-x if i & 1 else x)

    v = P[N]
    for k in range(N - 1, 1, -1):
        if k & 1:
            v = fmin(P[k], v)
        else:
            v = fmax(P[k], v)
    return v


TT = 1
TT = rint()
for tc in range(TT):
    ans = solve()

    print(ans)
    # print(*ans)
    # print("Yes" if ans else "No")

Information

Submit By
Type
Submission
Problem
P1208 C. Game on Integer
Contest
Educational Round 1
Language
PyPy 3 (Python 3.9.18 PyPy 7.3.15)
Submit At
2025-07-14 15:54:22
Judged At
2025-07-14 15:54:22
Judged By
Score
100
Total Time
144ms
Peak Memory
42.98 MiB