Accepted
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