aboutsummaryrefslogtreecommitdiff
path: root/codechef/EvenEqualOdd/main.cpp
blob: 9880c371e8b79d9f9ad2fcbb9c1ab03cef27fb60 (plain)
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
#include<bits/stdc++.h>

using namespace std;

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt;
	cin >> tt;
	while(tt--){
    int n;
    cin >> n;
    vector<int> v(n * 2);
    vector<int> even;
    int ev = 0;
    int odd = 0;
    for(int &x : v) {
      cin >> x;
      ev += (x % 2 == 0);
      odd += (x % 2 != 0);
      if(x % 2 == 0) {
        even.push_back(x);
      }
    }
    vector<int> op;
    for(int i = 0; i < even.size(); i++) {
      int count = 1;
      while((even[i] / 2 % 2) != 1) {
        count++;
        even[i] /= 2;
      }
      op.push_back(count);
    }
    sort(op.begin(), op.end());
    if(ev == odd) {
      cout << 0 << endl;
    } else if(ev > odd){
      int ans = 0;
      for(int i = 0; i < (ev - odd) / 2; i++) {
        ans += op[i];
      }
      cout << ans << endl;
    } else {
      cout << abs(ev - odd) / 2 << endl;
    }
	}
}