/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 18ms 532.0 KiB
#6 Accepted 15ms 532.0 KiB
#7 Accepted 48ms 1.27 MiB
#8 Accepted 39ms 1.27 MiB
#9 Accepted 36ms 1.27 MiB
#10 Accepted 37ms 1.316 MiB
#11 Accepted 11ms 580.0 KiB
#12 Accepted 13ms 532.0 KiB
#13 Accepted 20ms 1.27 MiB
#14 Accepted 39ms 1.273 MiB
#15 Accepted 13ms 532.0 KiB
#16 Accepted 15ms 396.0 KiB
#17 Accepted 15ms 532.0 KiB

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