/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 364.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 15ms 576.0 KiB
#6 Accepted 11ms 532.0 KiB
#7 Accepted 41ms 2.02 MiB
#8 Accepted 39ms 2.02 MiB
#9 Accepted 40ms 2.02 MiB
#10 Accepted 36ms 2.02 MiB
#11 Wrong Answer 34ms 588.0 KiB
#12 Wrong Answer 12ms 576.0 KiB

Code

#pragma GCC optimize("O3", "inline")
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
#define pb push_back
#define ub upper_bound
#define INF 1e18 + 100

ll solve()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    sort(a.begin(), a.end());
    int cnt = 0;
    for(int i = n - 1; i >= 0; i--){
        if(a[i] <= 0){
            if(cnt >= 2) return ans;
            if(cnt == 0) return a[n - 2] - a[n - 1];
            return ans + ((n - i - 1) % 2 == 0 ? a[i] : -a[i]);
        } 
        cnt++;
        ans += ((n - i - 1) % 2 == 0 ? a[i] : -a[i]);
    }
    return ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while(t--)
    {
        ll x = solve();
        cout << x << "\n";
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1208 C. Game on Integer
Language
C++17 (G++ 13.2.0)
Submit At
2025-07-15 05:15:01
Judged At
2025-07-15 05:15:01
Judged By
Score
60
Total Time
41ms
Peak Memory
2.02 MiB