aboutsummaryrefslogtreecommitdiff
path: root/contests/Round828/Round#828/C/main.cpp
blob: a69f2655f5765259801787fbc1c48fe14e3554ca (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
48
#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;
    int m = 0, mx = 0;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      while (x % 2 == 0) {
        x /= 2;
        m += 1;
      }
    }
    if (m >= n) {
      cout << 0 << '\n';
    } else {
      int d = n - m, ans = 0;
      vector<int> a;
      for (int i = n; i >= 1; i--) {
        int j = i, cnt = 0;
        while (j % 2 == 0) {
          cnt += 1;
          j /= 2;
        }
        if (cnt != 0) {
          a.push_back(cnt);
        }
      }
      sort(a.rbegin(), a.rend());
      for (int i = 0; i < (int)a.size(); i++) {
        ans += 1;
        d -= a[i];
        if (d <= 0) {
          break;
        }
      }
      cout << (d <= 0 ? ans : -1) << '\n';
    }
	}
}