/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 2ms 532.0 KiB
#5 Accepted 29ms 588.0 KiB
#6 Accepted 13ms 532.0 KiB
#7 Accepted 46ms 2.02 MiB
#8 Accepted 38ms 2.02 MiB
#9 Accepted 63ms 2.02 MiB
#10 Accepted 35ms 2.02 MiB
#11 Wrong Answer 11ms 536.0 KiB
#12 Wrong Answer 34ms 576.0 KiB

Code

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// #define int long long
const int MOD = 1000000007;
#define sz(x) (ll)(x).size()
#define rd ({ll x; cin >> x; x; })
#define dbg(x) cerr << "[" #x "]  " << (x) << "\n"
// #define errv(x) {cerr << "["#x"]  ["; for (const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
// #define cerr if(0)cerr
#define xx first
#define yy second
mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
/*_________________________________________________________________________________________________________________________*/

void Solve()
{
    ll n;
    cin >> n;
    vector<ll> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    sort(arr.rbegin(), arr.rend());
    ll ans = 0, mx = 0;
    for (int i = 0; i < n; i += 2) {
        mx = max(mx, ans);
        ans += arr[i];
        ll ans1 = ans;
        if (i + 1 < n)
            ans -= arr[i + 1];
        ll ans2 = ans;
        mx = max(mx, min(ans1, ans2));
        if (ans2 > ans1)
            break;
    }
    cout << mx << "\n";
}

int32_t main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": "; // cout << "Case " << i << ": ";
        Solve();
    }
    return 0;
}
// Coded by Tahsin Arafat (@TahsinArafat)

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:01:38
Judged At
2025-07-14 16:01:38
Judged By
Score
60
Total Time
63ms
Peak Memory
2.02 MiB