/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 34ms 17.363 MiB
#2 Accepted 35ms 17.336 MiB
#3 Accepted 35ms 17.258 MiB
#4 Accepted 38ms 17.34 MiB
#5 Accepted 61ms 18.539 MiB
#6 Accepted 57ms 18.477 MiB
#7 Accepted 98ms 39.508 MiB
#8 Accepted 117ms 41.449 MiB
#9 Accepted 118ms 42.426 MiB
#10 Accepted 111ms 42.539 MiB
#11 Accepted 92ms 20.289 MiB
#12 Accepted 88ms 19.57 MiB
#13 Accepted 77ms 40.551 MiB
#14 Accepted 123ms 40.879 MiB
#15 Accepted 101ms 20.344 MiB
#16 Accepted 95ms 20.039 MiB
#17 Accepted 75ms 18.492 MiB

Code

# ruff: noqa: E731, E741
from math import inf
import sys

read = sys.stdin.readline
input = lambda: read().rstrip()
ir = lambda: int(read())
rir = lambda: range(int(read()))
mir = lambda: map(int, read().split())
lmir = lambda: list(map(int, read().split()))


def solve():
    n = ir()
    a = sorted(mir())
    s = sum(a[-1::-2]) - sum(a[-2::-2])
    if n == 2:
        print(s)
        return
    roy = hridoy = s
    roy_turn = n % 2 == 1
    for ai in a[:-2]:
        # print(roy, hridoy, s, "roy" if roy_turn else "hridoy")
        if roy_turn:
            s -= ai
            roy = max(hridoy, s)
        else:
            s += ai
            hridoy = min(roy, s)
        roy_turn = not roy_turn
    # print(roy, hridoy, s)
    print(roy)
    # print()


def main():
    for _ in rir():
        solve()


def test():
    pass


if __name__ == "__main__":
    if sys.stdin.isatty():
        test()
    else:
        main()

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 16:04:23
Judged At
2025-07-14 16:04:23
Judged By
Score
100
Total Time
123ms
Peak Memory
42.539 MiB