/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 320.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 37ms 592.0 KiB
#6 Accepted 10ms 532.0 KiB
#7 Accepted 24ms 2.824 MiB
#8 Accepted 40ms 2.812 MiB
#9 Accepted 38ms 2.812 MiB
#10 Accepted 37ms 2.816 MiB
#11 Accepted 31ms 576.0 KiB
#12 Accepted 42ms 576.0 KiB
#13 Accepted 21ms 2.77 MiB
#14 Accepted 65ms 2.812 MiB
#15 Accepted 55ms 532.0 KiB
#16 Accepted 31ms 580.0 KiB
#17 Accepted 15ms 536.0 KiB

Code

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
cin>>T;
    while (T--) {
        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>());
        ll S = 0;

        vector<ll> dp(N+1, 0);
        dp[N]=0;
        for(int i=N-1;i>=2;i--) {
            dp[i]=0;
            if (i%2==0) {
                dp[i]=max(dp[i],dp[i+1]+A[i]); // roy
            } else {
                dp[i]=min(dp[i],dp[i+1]-A[i]); // hridoy
            }
        }
        cout << A[0]-A[1]+dp[2] << endl;
    }
    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:51:35
Judged At
2025-07-14 16:51:35
Judged By
Score
100
Total Time
65ms
Peak Memory
2.824 MiB