/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 316.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 340.0 KiB
#5 Accepted 33ms 532.0 KiB
#6 Accepted 10ms 532.0 KiB
#7 Accepted 21ms 2.066 MiB
#8 Accepted 58ms 2.066 MiB
#9 Accepted 36ms 2.02 MiB
#10 Accepted 52ms 2.02 MiB
#11 Accepted 11ms 616.0 KiB
#12 Accepted 11ms 584.0 KiB
#13 Accepted 20ms 2.02 MiB
#14 Accepted 37ms 2.02 MiB
#15 Accepted 12ms 532.0 KiB
#16 Accepted 14ms 624.0 KiB
#17 Accepted 13ms 596.0 KiB

Code

/**
*    In the name of Allah
*    We are nothing and you're everything
*    Ya Muhammad!
**/
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ull = uint64_t;
 
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define int long long
 
const char nl = '\n';
const int N = 1e5+5;
const ll inf = 0x3f3f3f3f3f3f3f3fll;

void solve() {
	int n; cin >> n;
	vector<int> a(n);
	for (auto &i: a)cin >> i;
	
	sort(all(a));
	int sum = a.back();
	a.pop_back();
	sum = sum-a.back();
	a.pop_back();
	n = sz(a);
	int turn = 0;
	for (int i = n-1; i >= 0; --i) {
		if (a[i] < 0)break;
		if (turn == 0)sum += a.back();
		else sum -= a.back();
		a.pop_back();
		turn = 1-turn;
	}
	
	cout << sum << nl;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t; 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 16:37:16
Judged At
2025-07-14 16:37:17
Judged By
Score
100
Total Time
58ms
Peak Memory
2.066 MiB