-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF_UnitArray.cpp
More file actions
43 lines (39 loc) · 841 Bytes
/
Copy pathCF_UnitArray.cpp
File metadata and controls
43 lines (39 loc) · 841 Bytes
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
#include <bits/stdc++.h> //1834A
using namespace std;
int main(){
int t,j;
cin>>t;
for ( j = 0; j < t; j++)
{
int n,i,sum=0,nop=0,noc=0,prod=1;
cin>>n;
int arr[n];
// Sum part
for ( i = 0; i < n; i++){
cin>>arr[i];
sum+=arr[i];
}
if(sum<0){
do{
sum+=2;
nop++;
}while(sum<0);
}
// Product part
for ( i = 0; i < n; i++){
prod=prod*arr[i];
}
if(nop%2==0){
if(prod!=1){
nop++;
}
}
else{
if(prod==1){
nop++;
}
}
printf("%d\n", nop);
}
return 0;
}