Accepted
Code
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<long long>v(n);
for(int i = 0; i < n; i++){
cin >> v[i];
}
sort(v.rbegin(),v.rend());
vector<long long>ans;
long long sum = v[0] - v[1];
if(n == 2){
cout << sum << "\n";
}
else{
for(int i = 2; i < n; i++){
if(i%2 == 0){
if(v[i] > 0){
sum += v[i];
}
else{
cout << sum << "\n";
return;
}
}
else{
if(v[i] > 0){
sum -= v[i];
}
else{
cout << sum << "\n";
return;
}
}
}
cout << sum << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.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 16:11:06
- Judged At
- 2025-07-14 16:11:06
- Judged By
- Score
- 100
- Total Time
- 54ms
- Peak Memory
- 2.059 MiB