-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Unit_Array.cpp
More file actions
102 lines (92 loc) · 4.85 KB
/
Copy pathA_Unit_Array.cpp
File metadata and controls
102 lines (92 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <bits/stdc++.h>
using namespace std;
#define iamspeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR(i, j, n) for(int i = j; i < n; i++)
#define trav(i, a) for(auto &i: a) cin >> i;
#define all(x) x.begin(), x.end()
#define reverse_sort(v) sort(all(v),greater<int>())
#define prnt(v) for(auto&i:v) cout << i << " ";
#define take(v) for(auto &i : v ) cin >> i
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define F first
#define S second
#define GCD __gcd
#define DEBUG(i) cout << "DEBUG " << i << "\n";
#define sorted(x) is_sorted(x.begin(),x.end())
#define BS(v,n) binary_search(v.begin(),v.end(),n)
#define trans(x,y) transform(all(x),x.begin(),:: y)
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
const ll MOD = 998244353;
const ll INF = 1e18;
void solve(){
ll cntn=0,cntp=0,ans=0;
ll n;
cin >> n;
vll v(n);
take(v);
FOR(i,0,n)
{
if(v[i]==1) cntp++;
else cntn++;
ans+=v[i];
}
if(ans>=0)
{
if(cntn%2==0)
cout << 0 << endl;
else
cout << 1 << endl;
}
else{
ans=abs(ans);
if(ans%2)
ans=ans/2+1;
else
ans=ans/2;
cntn-=ans;
if(cntn%2)
cout << ans+1 << endl;
else
cout << ans << endl;
}
}
int main()
{
iamspeed
// freopen("div7.in", "r", stdin);
// freopen("div7.out", "w", stdout);
// precompute();
int t=1;
cin >> t;
while(t--){
solve();
}
return 0;
}
/*
▄▄▄▄ ▄▄▄ ███▄ █ ██ ▄█▀▄▄▄ ██▓
▓█████▄ ▒████▄ ██ ▀█ █ ██▄█▒▒████▄ ▓██▒
▒██▒ ▄██▒██ ▀█▄ ▓██ ▀█ ██▒▓███▄░▒██ ▀█▄ ▒██▒
▒██░█▀ ░██▄▄▄▄██ ▓██▒ ▐▌██▒▓██ █▄░██▄▄▄▄██ ░██░
░▓█ ▀█▓ ▓█ ▓██▒▒██░ ▓██░▒██▒ █▄▓█ ▓██▒░██░
░▒▓███▀▒ ▒▒ ▓▒█░░ ▒░ ▒ ▒ ▒ ▒▒ ▓▒▒▒ ▓▒█░░▓
▒░▒ ░ ▒ ▒▒ ░░ ░░ ░ ▒░░ ░▒ ▒░ ▒ ▒▒ ░ ▒ ░
░ ░ ░ ▒ ░ ░ ░ ░ ░░ ░ ░ ▒ ▒ ░
░ ░ ░ ░ ░ ░ ░ ░ ░
░
▄████▄ ▒█████ ▓█████▄ ▓█████ █████▒██▓ ███▄ █ ██▓ ██████ ██░ ██ ▓█████ ▓█████▄
▒██▀ ▀█ ▒██▒ ██▒▒██▀ ██▌▓█ ▀ ▓██ ▒▓██▒ ██ ▀█ █ ▓██▒▒██ ▒ ▓██░ ██▒▓█ ▀ ▒██▀ ██▌
▒▓█ ▄ ▒██░ ██▒░██ █▌▒███ ▒████ ░▒██▒▓██ ▀█ ██▒▒██▒░ ▓██▄ ▒██▀▀██░▒███ ░██ █▌
▒▓▓▄ ▄██▒▒██ ██░░▓█▄ ▌▒▓█ ▄ ░▓█▒ ░░██░▓██▒ ▐▌██▒░██░ ▒ ██▒░▓█ ░██ ▒▓█ ▄ ░▓█▄ ▌
▒ ▓███▀ ░░ ████▓▒░░▒████▓ ░▒████▒ ░▒█░ ░██░▒██░ ▓██░░██░▒██████▒▒░▓█▒░██▓░▒████▒░▒████▓
░ ░▒ ▒ ░░ ▒░▒░▒░ ▒▒▓ ▒ ░░ ▒░ ░ ▒ ░ ░▓ ░ ▒░ ▒ ▒ ░▓ ▒ ▒▓▒ ▒ ░ ▒ ░░▒░▒░░ ▒░ ░ ▒▒▓ ▒
░ ▒ ░ ▒ ▒░ ░ ▒ ▒ ░ ░ ░ ░ ▒ ░░ ░░ ░ ▒░ ▒ ░░ ░▒ ░ ░ ▒ ░▒░ ░ ░ ░ ░ ░ ▒ ▒
░ ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ▒ ░░ ░ ░ ░ ░░ ░ ░ ░ ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
░ ░ ░
*/