/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 42ms 17.934 MiB
#2 Accepted 41ms 17.977 MiB
#3 Accepted 41ms 17.934 MiB
#4 Accepted 41ms 17.945 MiB
#5 Wrong Answer 84ms 19.625 MiB
#6 Wrong Answer 64ms 19.094 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)
    if N == 2:
        return A[0] - A[1]

    half = (N + 1) // 2
    P = [0] * (half + 1)
    Q = [0] * (half + 1)

    for i in range(1, half + 1):
        P[i] = P[i - 1] + A[2 * (i - 1)]
        j = 2 * (i - 1) + 1
        Q[i] = Q[i - 1]
        if j < N:
            Q[i] += A[j]

    ans = max(P[i] - Q[i - 1] for i in range(2, half + 1))
    return max(0, ans)


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:41:07
Judged At
2025-07-14 15:41:07
Judged By
Score
5
Total Time
84ms
Peak Memory
19.625 MiB