/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 536.0 KiB
#3 Accepted 1ms 344.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Wrong Answer 25ms 536.0 KiB
#6 Wrong Answer 21ms 532.0 KiB

Code

#include <bits/stdc++.h>

using namespace std;

void solve(int cs) {
  int n;
  cin >> n;
  multiset<int> pos, neg;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x >= 0) {
      pos.insert(x);
    } else {
      neg.insert(x);
    }
  }
  const int64_t INF = -1e18;
  int64_t s = 0;
  int t = 1;
  vector<int64_t> seq;
  while (pos.size() || neg.size()) {
    pair<int64_t, int64_t> P = {INF, INF};
    if (!t) P = {-INF, -INF};
    if (pos.size()) {
      if (t) {
        P.first = s + *pos.begin();
        P.second = s + *pos.rbegin();
      } else {
        P.first = s - *pos.begin();
        P.second = s - *pos.rbegin();
      }
    } 
    pair<int64_t, int64_t> N = {INF, INF};
    if (!t) N = {-INF, -INF};
    if (neg.size()) {
      if (t) {
        N.first = s + *neg.begin();
        N.second = s + *neg.rbegin();
      } else {
        N.first = s - *neg.begin();
        N.second = s - *neg.rbegin();
      }
    }
    if (t) {
      int64_t mx = max({P.first, N.first, N.second, P.second});
      if (P.first == mx) {
        pos.erase(pos.begin());
      } else if (P.second == mx) {
        pos.erase(--pos.end());
      } else if (N.first == mx) {
        neg.erase(neg.begin());
      } else {
        neg.erase(--neg.end());
      }
      seq.push_back(mx);
      s = mx;
    } else {
      int64_t mn = min({P.first, N.first, N.second, P.second});
      if (P.first == mn) {
        pos.erase(pos.begin());
      } else if (P.second == mn) {
        pos.erase(--pos.end());
      } else if (N.first == mn) {
        neg.erase(neg.begin());
      } else {
        neg.erase(--neg.end());
      }      
      seq.push_back(mn);
      s = mn;
    }
    t ^= 1;
  }
  cout << seq[1] << "\n";
}

int32_t main() {
  cin.tie(0) -> sync_with_stdio(0);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
  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:05:33
Judged At
2025-07-14 17:05:33
Judged By
Score
5
Total Time
25ms
Peak Memory
536.0 KiB