/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 552.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 584.0 KiB
#7 Accepted 23ms 3.52 MiB
#8 Accepted 41ms 3.57 MiB
#9 Accepted 39ms 3.52 MiB
#10 Accepted 38ms 3.562 MiB
#11 Accepted 28ms 592.0 KiB
#12 Accepted 21ms 568.0 KiB
#13 Accepted 21ms 3.578 MiB
#14 Accepted 41ms 3.578 MiB
#15 Accepted 29ms 532.0 KiB
#16 Accepted 31ms 588.0 KiB
#17 Accepted 16ms 532.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long int

int find_max_freq(vector<int> cnt) {
    int max_f = 0;
    for (int count : cnt) {
        if (count > max_f) {
            max_f = count;
        }
    }
    return max_f;
}

int solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    vector<int> scores(n + 1, 0);
    for (int k = 1; k <= n; ++k) {
        if (k % 2 != 0) {
            scores[k] = scores[k - 1] + a[k - 1];
        } else {
            scores[k] = scores[k - 1] - a[k - 1];
        }
    }

    int V = scores[n];
    for (int k = n - 1; k >= 2; --k) {
        if (k % 2 == 0) {
            V = max(scores[k], V);
        } else {
            V = min(scores[k], V);
        }
    }

    cout << V << endl;
    return 0;
}
int32_t main(){
    ios::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
 
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    

    int t;
    t = 1;
    cin>>t;
    while(t--){
        solve();
    }
    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 16:35:43
Judged At
2025-07-14 16:35:43
Judged By
Score
100
Total Time
41ms
Peak Memory
3.578 MiB