/ 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 436.0 KiB
#4 Accepted 1ms 436.0 KiB
#5 Accepted 15ms 532.0 KiB
#6 Accepted 11ms 584.0 KiB
#7 Accepted 27ms 2.68 MiB
#8 Accepted 43ms 2.594 MiB
#9 Accepted 53ms 2.613 MiB
#10 Accepted 49ms 2.637 MiB
#11 Wrong Answer 12ms 532.0 KiB
#12 Wrong Answer 12ms 532.0 KiB

Code

#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("O3")

typedef long long ll;
typedef unsigned int ull;
typedef long double lld;

#define int long long

/*---------------------------------------------------------------------------------------------------------------------------------------------*/
#ifdef ONLINE_JUDGE
#define debug(x)
#else
#define debug(x)       \
    cerr << #x << " "; \
    _print(x);         \
    cerr << endl;
#endif

#define int long long
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define fastio()                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define setbits(x) __builtin_popcountll(x)

const int MOD = 1e9 + 7;

void _print(ll t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(lld t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(ull t) { cerr << t; }

template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p)
{
    cerr << "{";
    _print(p.ff);
    cerr << ",";
    _print(p.ss);
    cerr << "}";
}
template <class T>
void _print(vector<T> v)
{
    cerr << "[ ";
    for (T i : v)
    {
        _print(i);
        cerr << " ";
    }
    cerr << "]";
}
template <class T>
void _print(set<T> v)
{
    cerr << "[ ";
    for (T i : v)
    {
        _print(i);
        cerr << " ";
    }
    cerr << "]";
}
template <class T>
void _print(multiset<T> v)
{
    cerr << "[ ";
    for (T i : v)
    {
        _print(i);
        cerr << " ";
    }
    cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v)
{
    cerr << "[ ";
    for (auto i : v)
    {
        _print(i);
        cerr << " ";
    }
    cerr << "]";
}

vector<int> vinput(int n)
{
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    return v;
}

void printVector(vector<int> &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i] << " ";
    }
    cout << '\n';
}

int ceilCustom(int a, int b)
{
    return (a + b - 1) / b;
}

/*--------------------------  CODE HERE -------------------------------------------------------------------------------------------------------------------*/

bool isPalindrome(string v, int l, int r)
{
    while (l < r)
    {
        if (v[l++] != v[r--])
            return false;
    }
    return true;
}

bool possible(vector<int>& cnt, int rem) {
    int mx = *max_element(cnt.begin(), cnt.end());
    return mx <= (rem + 1) / 2;
}

void solve() {
    int n;
    cin >> n;
    priority_queue<int> pq;

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        pq.push(x);
    }

    int s = 0, flag = 0, move = 0;
    while (!pq.empty() && pq.top() > 0) {
        int x = pq.top();
        if (x < 0 && move >= 2) {
            break;
        }
        pq.pop();
        if (flag == 0) s += x;
        else s -= x;
        move++;
        flag ^= 1;
    }

    cout << s << '\n';
}

signed main()
{

    fastio();

    int t = 1;
    cin >> t;

    while (t--)
    {
        solve();
    }

    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:26:05
Judged At
2025-07-14 17:26:05
Judged By
Score
60
Total Time
53ms
Peak Memory
2.68 MiB