/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 35ms 17.344 MiB
#2 Accepted 35ms 17.207 MiB
#3 Accepted 35ms 17.246 MiB
#4 Accepted 35ms 17.246 MiB
#5 Accepted 63ms 18.789 MiB
#6 Accepted 58ms 18.488 MiB
#7 Accepted 93ms 39.641 MiB
#8 Accepted 115ms 41.438 MiB
#9 Accepted 109ms 43.047 MiB
#10 Accepted 118ms 41.148 MiB
#11 Accepted 176ms 23.742 MiB
#12 Accepted 134ms 21.145 MiB
#13 Accepted 76ms 39.441 MiB
#14 Accepted 116ms 40.941 MiB
#15 Accepted 141ms 20.723 MiB
#16 Accepted 145ms 20.301 MiB
#17 Accepted 76ms 19.242 MiB

Code

T = int(input())
for _ in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    ans = A[-1]-A[-2]
    A.pop()
    A.pop()
    flag = True
    for i in range(len(A)-1,-1,-1):
        if A[i]<=0:
            break
        if flag:
            ans += A[i]
            flag = not flag
        else:
            ans -= A[i]
            flag = not flag
    print(ans)

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:34:49
Judged At
2025-07-14 16:34:49
Judged By
Score
100
Total Time
176ms
Peak Memory
43.047 MiB