/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 35ms 17.32 MiB
#2 Accepted 54ms 17.246 MiB
#3 Accepted 41ms 17.402 MiB
#4 Accepted 35ms 17.234 MiB
#5 Accepted 65ms 18.457 MiB
#6 Accepted 60ms 18.527 MiB
#7 Accepted 98ms 40.113 MiB
#8 Accepted 122ms 43.543 MiB
#9 Accepted 113ms 43.215 MiB
#10 Accepted 120ms 41.242 MiB
#11 Wrong Answer 91ms 19.449 MiB
#12 Wrong Answer 77ms 19.039 MiB

Code

import sys

input = lambda: sys.stdin.readline().strip()

def print(value):
    sys.stdout.write(str(value) + '\n')

def printl(l):
    print(''.join(str(y) for y in l))

def rl():
    return(map(int,input().split()))

for _ in range(int(input())):
    n=int(input())
    a=list(rl())

    a.sort()
    s=n
    e=0

    for i in range(n):
        if (n-i)%2:
            e-=a[i]
            if e>=0:
                s=n-i-1
                e=0
        else:
            e+=a[i]
            if e<=0:
                s=n-i-1
                e=0
    a.reverse()
    e=0
    for i in range(s):
        if i%2:
            e-=a[i]
        else:
            e+=a[i]
    
    print(e)

        

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:49:50
Judged At
2025-07-14 15:49:50
Judged By
Score
60
Total Time
122ms
Peak Memory
43.543 MiB