fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  5. #define int long long
  6. #define endl '\n'
  7.  
  8. const int INF = 1e18;
  9. const int N = 35;
  10.  
  11. int a[N];
  12.  
  13. void solve() {
  14. int n, c;
  15. cin >> n >> c;
  16.  
  17. for (int i = 0; i < n; ++i) cin >> a[i];
  18. sort(a, a + n); // Sort ascending
  19.  
  20. int min_coins = INF;
  21.  
  22. // Try destroying the last i elements last (letting them double)
  23. for (int last_heavy = 0; last_heavy <= n; ++last_heavy) {
  24. int coins = 0;
  25. for (int j = 0; j < n; ++j) {
  26. int k = max(0LL, j - (n - last_heavy)); // how many doublings
  27. int val = a[j];
  28. if (k >= 60) val = INF; // prevent overflow
  29. else val <<= k;
  30.  
  31. if (val > c) coins++;
  32. }
  33. min_coins = min(min_coins, coins);
  34. }
  35.  
  36. cout << min_coins << endl;
  37. }
  38.  
  39. int32_t main() {
  40. fast_io;
  41.  
  42. int t;
  43. cin >> t;
  44. while (t--) {
  45. solve();
  46. }
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0.01s 5292KB
stdin
4
5 10
10 4 15 1 8
3 42
1000000000 1000000000 1000000000
10 30
29 25 2 12 15 42 14 6 16 9
10 1000000
1 1 1 1 1 1 1 1 1 864026633
stdout
1
3
1
1