/ 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 38ms 580.0 KiB
#6 Wrong Answer 10ms 532.0 KiB

Code

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

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> arr(n);
        for (int i = 0; i < n; i++)
            cin >> arr[i];
        sort(arr.rbegin(), arr.rend());
        int res = arr[0] - arr[1];
        int i = 2;

        vector<int> suffix(n, 0);
        for (int i = n - 1; i >= 0; i--)
        {
            suffix[i] += arr[i];
            if (i < n - 1)
                suffix[i] += suffix[i + 1];
        }
        bool ok = 1;
        while (i < n)
        {
            if (ok)
            {
                ok = false;
                if (suffix[i] > 0)
                {
                    res += arr[i];
                }
                else
                    break;
            }
            else
            {
                ok = 1;
                if (suffix[i] <= 0)
                {
                    res -= arr[i];
                }
                else
                    break;
            }
            i++;
        }

        cout << res << endl;
    }
    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:22:19
Judged At
2025-07-14 17:22:19
Judged By
Score
5
Total Time
38ms
Peak Memory
580.0 KiB