Accepted
Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve();
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int tc; cin >> tc;
for (int tt = 0; tt < tc; tt++) solve();
return 0;
}
void solve() {
int n; cin >> n;
vector<int> a(n);
for (int &x : a) cin >> x;
sort(a.begin(), a.end(), greater<int>());
ll ans = a[0] - a[1];
for (int i = 2; i < n; i++) {
if (a[i] > 0) {
if (i & 1) ans -= a[i];
else ans += a[i];
}
}
cout << ans << "\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:06:29
- Judged At
- 2025-07-14 16:06:29
- Judged By
- Score
- 100
- Total Time
- 48ms
- Peak Memory
- 1.316 MiB