/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 336.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 14ms 324.0 KiB
#6 Accepted 10ms 572.0 KiB
#7 Accepted 27ms 1.836 MiB
#8 Accepted 41ms 2.02 MiB
#9 Accepted 36ms 1.836 MiB
#10 Accepted 60ms 2.066 MiB
#11 Accepted 11ms 624.0 KiB
#12 Accepted 11ms 532.0 KiB
#13 Accepted 23ms 2.078 MiB
#14 Accepted 42ms 2.074 MiB
#15 Accepted 12ms 532.0 KiB
#16 Accepted 14ms 532.0 KiB
#17 Accepted 13ms 564.0 KiB

Code

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

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tc; cin >> tc;

    test:
    while (tc--) {
        ll n; cin >> n;
        
        ll arr[n];
        for (auto &u : arr) cin >> u;
        sort(arr, arr+n);
        reverse(arr, arr+n);

        if (n == 2) {
            cout << arr[0] - arr[1] << "\n";
            goto test;
        }
        
        ll temp = arr[0]-arr[1];
        for (ll i = 2; i < n; i++) {
            if (i & 1) {
                if (temp - arr[i] > temp) break;
                else temp -= arr[i];
            }
            else {
                if (temp + arr[i] < temp) break;
                else temp += arr[i];
            }
        }

        cout << temp << "\n";
        
    }
}

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:46:51
Judged At
2025-07-14 16:46:51
Judged By
Score
100
Total Time
60ms
Peak Memory
2.078 MiB