/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 316.0 KiB
#2 Accepted 1ms 392.0 KiB
#3 Accepted 1ms 368.0 KiB
#4 Accepted 1ms 444.0 KiB
#5 Accepted 15ms 532.0 KiB
#6 Accepted 11ms 532.0 KiB
#7 Accepted 31ms 3.57 MiB
#8 Accepted 41ms 3.52 MiB
#9 Accepted 40ms 3.582 MiB
#10 Accepted 38ms 3.523 MiB
#11 Accepted 27ms 372.0 KiB
#12 Accepted 40ms 532.0 KiB
#13 Accepted 21ms 3.582 MiB
#14 Accepted 44ms 3.52 MiB
#15 Accepted 28ms 320.0 KiB
#16 Accepted 30ms 536.0 KiB
#17 Accepted 41ms 628.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 (arr[i] >= 0)
                {
                    res += arr[i];
                }
                else
                    break;
            }
            else
            {
                ok = true;
                if (arr[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:27:40
Judged At
2025-07-14 17:27:40
Judged By
Score
100
Total Time
44ms
Peak Memory
3.582 MiB