/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 368.0 KiB
#3 Accepted 1ms 320.0 KiB
#4 Accepted 1ms 536.0 KiB
#5 Wrong Answer 16ms 532.0 KiB
#6 Wrong Answer 12ms 532.0 KiB

Code

#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
using namespace std;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define int long long

void del(multiset <int> &ms , int val) {
  ms.erase(ms.find(val)) ;
}

void solve() {
  
    int n ;
    cin >> n ;
    vector <int> a(n) ;
    for(int i = 0 ; i < n ; i ++) cin >> a[i] ;
    sort(a.begin() , a.end()) ;
    reverse(a.begin() , a.end()) ;
    int ans = a[0] - a[1] ;
    int fans = ans ;
    for(int i = 2 ; i < n ; i ++) {
      if(a[i] <= 0) break ;
      if(i % 2 == 0) {
        ans += a[i] ;
        fans = min(fans , ans) ;
      } else {
        ans -= a[i] ;
      }
    }
    cout << fans << endl ;
  
}
       
     
      









int32_t main() {

    fastio();
    int t = 1;
    cin >> t;
    while (t--) solve();
}

Information

Submit By
Type
Submission
Problem
P1208 C. Game on Integer
Language
C++17 (G++ 13.2.0)
Submit At
2025-07-14 18:12:19
Judged At
2025-07-14 18:12:19
Judged By
Score
5
Total Time
16ms
Peak Memory
536.0 KiB