/ 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 488.0 KiB
#5 Wrong Answer 53ms 320.0 KiB
#6 Wrong Answer 19ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
 
 
const int MOD = 1e9 + 7;
const int MX = 1e6 + 10;
long long dp[MX + 100][2];
 
 
void solve(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int &i : a) cin >> i;
  sort(a.begin(),a.end());
  if(a[n-2] < 0){
    cout << a[n-1] - a[n-2] << endl;
    return;
  }
  else{
    long long ans1 = 0; // max
    long long ans2 = 1e18; // min
    int i = n-3;
    int turn = 0;
    long long score = a[n-1] - a[n-2];
    ans1 = max(ans1,score);
    while(i >= 0){
      if(turn == 0){
        ans1 = max(ans1,score);
        score += a[i];
      }
      else{
        ans2 = min(ans2,score);
        score -= a[i];
      }
      turn ^= 1;
      i--;
    }
    cout << min(ans1,ans2) << endl;
  }
  
  
  
}
 
 
 
 
int main()
{
    int 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 17:02:50
Judged At
2025-07-14 17:02:50
Judged By
Score
5
Total Time
53ms
Peak Memory
532.0 KiB