/ 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 532.0 KiB
#5 Wrong Answer 16ms 588.0 KiB
#6 Wrong Answer 12ms 532.0 KiB

Code

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

#define ll long long
#define int long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> v(n);
        f(i, n) cin >> v[i];
        sort(all(v));
        reverse(all(v));
        int r = -1e18, c = 1e18, s = 0, res = 1e18;
        f(i, n)
        {
            if (i & 1)
                s = min(s, s - v[i]);
            else
                s = max(s, s + v[i]), r = max(r, s);
            if (i > 0)
            {
                if (i & 1)
                    c = min(c, s);
                res = min({res, r, c});
            }
            // cout << s << ' ' << c << ' ' << r << ' ' << res << endl;
        }
        cout << res << endl;
    }
}

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 15:57:45
Judged At
2025-07-14 15:57:45
Judged By
Score
5
Total Time
16ms
Peak Memory
588.0 KiB