/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 15ms 532.0 KiB
#6 Accepted 11ms 536.0 KiB
#7 Accepted 23ms 1.27 MiB
#8 Accepted 39ms 1.316 MiB
#9 Accepted 38ms 1.27 MiB
#10 Accepted 39ms 1.27 MiB
#11 Wrong Answer 27ms 576.0 KiB
#12 Wrong Answer 20ms 568.0 KiB

Code

// Created: 2025-07-14 21:56:09 IST
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// #define int long long
#define ll long long
#define cout cout<<fixed<<setprecision(0)
#define pb push_back
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(a,n) for(int i=0; i<n; i++){ cin>>a[i]; }
#define ff(a,l,n) for(int i=l; i<=n; i++){ cin>>a[i]; }
#define vvi vector<vector<int>>
#define vi vector<int>
#define all(a) (a).begin(), (a).end()
#define minpq priority_queue<ll, vector<ll>, greater<ll>> ;
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void solve(){
    int n; cin>>n;
    vi a(n); f(a,n);
    sort(all(a));
    int curr=0;
    int idx=n-1;
    while(1){
        if(idx<0 || a[idx]<=0){
            break;
        }
        curr+=a[idx];
        --idx;
        if(idx<0 || a[idx]<=0){
            break;
        }
        curr-=a[idx];
        --idx;
    }
    cout<<curr<<endl;

}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    // solve();
    int t; cin>>t;
    for(int i=0; i<t; i++){
        solve();
    }
    
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    // cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\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:30:27
Judged At
2025-07-14 17:30:27
Judged By
Score
60
Total Time
39ms
Peak Memory
1.316 MiB