/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 444.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 16ms 320.0 KiB
#6 Accepted 12ms 532.0 KiB
#7 Accepted 23ms 1.066 MiB
#8 Accepted 37ms 1.316 MiB
#9 Accepted 36ms 1.27 MiB
#10 Accepted 41ms 1.312 MiB
#11 Accepted 11ms 532.0 KiB
#12 Accepted 12ms 532.0 KiB
#13 Accepted 21ms 1.27 MiB
#14 Accepted 42ms 1.27 MiB
#15 Accepted 13ms 532.0 KiB
#16 Accepted 15ms 532.0 KiB
#17 Accepted 20ms 532.0 KiB

Code

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) 
            cin >> a[i];

        sort(a.begin(), a.end(), greater<int>());

        long long S = 0;
        bool royPlayed = false, hrPlayed = false;
        bool royTurn = true;
        int idx = 0;

        while (idx < n) {
            int x = a[idx];

            if (royTurn) {
                if (!royPlayed || x > 0) {
                    S += x;
                    royPlayed = true;
                    idx++;
                } else {
                    break;
                }
            } else {
                if (!hrPlayed || x > 0) {
                    S -= x;
                    hrPlayed = true;
                    idx++;
                } else {
                    // stop
                    break;
                }
            }

            royTurn = !royTurn;
        }

        cout << S << "\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 17:13:47
Judged At
2025-07-14 17:13:47
Judged By
Score
100
Total Time
42ms
Peak Memory
1.316 MiB