/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 440.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 35ms 532.0 KiB
#6 Accepted 19ms 320.0 KiB
#7 Accepted 42ms 2.02 MiB
#8 Accepted 103ms 2.051 MiB
#9 Accepted 104ms 1.812 MiB
#10 Accepted 98ms 2.02 MiB
#11 Accepted 48ms 584.0 KiB
#12 Accepted 43ms 532.0 KiB
#13 Accepted 63ms 2.055 MiB
#14 Accepted 124ms 2.055 MiB
#15 Accepted 43ms 548.0 KiB
#16 Accepted 52ms 560.0 KiB
#17 Accepted 35ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;


int main() {

    long long t;
    cin>>t;

    while(t--)
    {
        long long n;
        cin>>n;
        long long a[n];
        for(long long i=0;i<n;i++) cin>>a[i];
        sort(a,a+n);
        long long ans=(a[n-1]-a[n-2]);
        long long T=0;
        for(long long i=n-3;i>=0;i--)
        {
            if(T==0)
            {
                if(ans+a[i]>ans)
                {
                    ans+=a[i];
                    T^=1;
                }
                else break;
            }
            else
            {
                if(ans-a[i]<ans)
                {
                    ans-=a[i];
                    T^=1;
                }
                else break;
            }
        }
        cout<<ans<<"\n";
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1208 C. Game on Integer
Contest
Educational Round 1
Language
C++17 (G++ 13.2.0)
Submit At
2025-07-14 16:35:45
Judged At
2025-07-14 16:35:45
Judged By
Score
100
Total Time
124ms
Peak Memory
2.055 MiB