-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminflips.cpp
More file actions
39 lines (37 loc) · 787 Bytes
/
minflips.cpp
File metadata and controls
39 lines (37 loc) · 787 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
#include <bits/stdc++.h>
using namespace std;
int main()
{
// your code goes here
// ia_anuj_10
int z;
cin >> z;
while (z--)
{
int n;
cin >> n;
int a[n];
for (int m = 0; m < n; m++)
cin >> a[m];
if (n % 2 == 1)
cout << -1 << endl;
else
{
int num1 = 0, num2 = 0;
// int num=num2-num1;
for (int m = 0; m < n; m++)
{
if (a[m] == 1)
num2++;
else
num1++;
}
int num = num2 - num1;
if (num1 == num2)
cout << 0 << endl;
else
cout << abs((num) / 2) << endl;
}
}
return 0;
}