-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Unit_Array.java
More file actions
135 lines (126 loc) · 6.73 KB
/
Copy pathA_Unit_Array.java
File metadata and controls
135 lines (126 loc) · 6.73 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import java.io.*;
import java.util.*;
public class A_Unit_Array {
// Fast IO in Java
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
static StringTokenizer st;
// Utility methods
static int nextInt() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return Integer.parseInt(st.nextToken());
}
static long nextLong() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return Long.parseLong(st.nextToken());
}
static Vector<Integer> readIntVector(int n) throws IOException {
Vector<Integer> vec = new Vector<>(n);
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) vec.add(Integer.parseInt(st.nextToken()));
return vec;
}
static Vector<Long> readLongVector(int n) throws IOException {
Vector<Long> vec = new Vector<>(n);
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) vec.add(Long.parseLong(st.nextToken()));
return vec;
}
static int[] readIntArray(int n) throws IOException {
int[] arr = new int[n];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) arr[i] = Integer.parseInt(st.nextToken());
return arr;
}
static long[] readLongArray(int n) throws IOException {
long[] arr = new long[n];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) arr[i] = Long.parseLong(st.nextToken());
return arr;
}
static <T> void printList(List<T> list) {
for (T i : list) out.print(i + " ");
out.println();
}
static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
static boolean isSorted(int[] arr) {
for (int i = 1; i < arr.length; i++) if (arr[i] < arr[i-1]) return false;
return true;
}
static boolean binarySearch(int[] arr, int key) {
return Arrays.binarySearch(arr, key) >= 0;
}
static void reverseSort(int[] arr) {
Arrays.sort(arr);
for (int i = 0, j = arr.length - 1; i < j; i++, j--) {
int tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp;
}
}
// Type aliases
// static final long MOD = 998244353;
// static final long INF = (long)1e18;
static void solve() throws IOException {
// Implement your solution here
int n=nextInt();
int cntn=0,cntp=0;
int []a=new int[n];
for(int i=0;i<n;i++)
{
a[i]=nextInt();
if(a[i]==1) cntp++;
else cntn++;
}
// System.out.println(cntn+" "+cntp);
int ans=0;
if(cntn%2==1)
{
cntn--;
cntp++;
ans=1;
}
while(true)
{ if(cntp>=cntn && cntn%2!=0){
cntn--;
cntp++;
ans++;}
else
break;
}
System.out.println(ans);
}
public static void main(String[] args) throws IOException {
int t = 1;
String line = br.readLine();
if (line != null && !line.isEmpty()) t = Integer.parseInt(line.trim());
while (t-- > 0) {
solve();
}
out.flush();
}
}
/*
▄▄▄▄ ▄▄▄ ███▄ █ ██ ▄█▀▄▄▄ ██▓
▓█████▄ ▒████▄ ██ ▀█ █ ██▄█▒▒████▄ ▓██▒
▒██▒ ▄██▒██ ▀█▄ ▓██ ▀█ ██▒▓███▄░▒██ ▀█▄ ▒██▒
▒██░█▀ ░██▄▄▄▄██ ▓██▒ ▐▌██▒▓██ █▄░██▄▄▄▄██ ░██░
░▓█ ▀█▓ ▓█ ▓██▒▒██░ ▓██░▒██▒ █▄▓█ ▓██▒░██░
░▒▓███▀▒ ▒▒ ▓▒█░░ ▒░ ▒ ▒ ▒ ▒▒ ▓▒▒▒ ▓▒█░░▓
▒░▒ ░ ▒ ▒▒ ░░ ░░ ░ ▒░░ ░▒ ▒░ ▒ ▒▒ ░ ▒ ░
░ ░ ░ ▒ ░ ░ ░ ░ ░░ ░ ░ ▒ ▒ ░
░ ░ ░ ░ ░ ░ ░ ░ ░
░
▄████▄ ▒█████ ▓█████▄ ▓█████ █████▒██▓ ███▄ █ ██▓ ██████ ██░ ██ ▓█████ ▓█████▄
▒██▀ ▀█ ▒██▒ ██▒▒██▀ ██▌▓█ ▀ ▓██ ▒▓██▒ ██ ▀█ █ ▓██▒▒██ ▒ ▓██░ ██▒▓█ ▀ ▒██▀ ██▌
▒▓█ ▄ ▒██░ ██▒░██ █▌▒███ ▒████ ░▒██▒▓██ ▀█ ██▒▒██▒░ ▓██▄ ▒██▀▀██░▒███ ░██ █▌
▒▓▓▄ ▄██▒▒██ ██░░▓█▄ ▌▒▓█ ▄ ░▓█▒ ░░██░▓██▒ ▐▌██▒░██░ ▒ ██▒░▓█ ░██ ▒▓█ ▄ ░▓█▄ ▌
▒ ▓███▀ ░░ ████▓▒░░▒████▓ ░▒████▒ ░▒█░ ░██░▒██░ ▓██░░██░▒██████▒▒░▓█▒░██▓░▒████▒░▒████▓
░ ░▒ ▒ ░░ ▒░▒░▒░ ▒▒▓ ▒ ░░ ▒░ ░ ▒ ░ ░▓ ░ ▒░ ▒ ▒ ░▓ ▒ ▒▓▒ ▒ ░ ▒ ░░▒░▒░░ ▒░ ░ ▒▒▓ ▒
░ ▒ ░ ▒ ▒░ ░ ▒ ▒ ░ ░ ░ ░ ▒ ░░ ░░ ░ ▒░ ▒ ░░ ░▒ ░ ░ ▒ ░▒░ ░ ░ ░ ░ ░ ▒ ▒
░ ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ▒ ░░ ░ ░ ░ ░░ ░ ░ ░ ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
░ ░ ░
*/