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>0){
t--;
long long n;
cin >> n;
vector<long long> a(n);
for(auto &nx : a){cin >> nx;}
sort(a.rbegin(),a.rend());
long long s=0;
for(long long i=0;i<n;i++){
if(i>=2 && a[i]<=0){break;}
if(i%2){s-=a[i];}
else{s+=a[i];}
}
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 15:43:29
- Judged At
- 2025-07-14 15:43:29
- Judged By
- Score
- 100
- Total Time
- 38ms
- Peak Memory
- 2.066 MiB