Accepted
Code
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n; cin >> n;
int a[n]; for (auto& x : a) cin >> x;
sort(a, a+n, greater<>());
long long S = 0;
for (int i = 0; i < n; i++) {
if (i >= 2 && a[i] < 0) break;
S += i & 1 ? -a[i] : a[i];
}
cout << S << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin >> t; while (t--)
solve();
}
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:15:56
- Judged At
- 2025-07-14 17:15:56
- Judged By
- Score
- 100
- Total Time
- 40ms
- Peak Memory
- 1.316 MiB