-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_One_and_Two.cpp
More file actions
50 lines (48 loc) · 807 Bytes
/
Copy pathA_One_and_Two.cpp
File metadata and controls
50 lines (48 loc) · 807 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
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
void resolu() {
long long a;
cin>>a;
vector<long long> aa(a);
long long contador=0;
long long contadorr=0;
long long contadorrr=0;
for (long long i=0;i<a;i++){
cin>>aa[i];
if (aa[i]==2){
contador=contador+1;
}
}
if (contador==0){
cout<<1<<endl;
}
else{
if(contador%2==0){
for (long long i=0;i<a;i++){
contadorrr=contadorrr+1;
if (aa[i]==2){
contadorr=contadorr+1;
}
if (contadorr==contador/2){
break;
}
}
if(contadorrr<=a-1){
cout<<contadorrr<<endl;
}
else{
cout<<-1<<endl;
}
}
else{
cout<<-1<<endl;
}
}
}
int main(){
long long t;
cin >> t;
while (t--){
resolu();
}
}