fork(1) 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 N = 35;
  9. const int INF = 1e18;
  10.  
  11. void solve() {
  12. int n, c;
  13. cin >> n >> c;
  14. int a[N];
  15. for (int i = 0; i < n; ++i) cin >> a[i];
  16.  
  17. priority_queue<pair<int, int>> pq; // {weight, index}
  18. int steps[N] = {0}; // How many times each has been doubled
  19. for (int i = 0; i < n; ++i) {
  20. pq.push({a[i], i});
  21. }
  22.  
  23. int coins = 0;
  24. while (!pq.empty()) {
  25. auto [w, idx] = pq.top();
  26. pq.pop();
  27.  
  28. // Recalculate actual weight after all doublings
  29. w = a[idx] << steps[idx];
  30. if (w > c) coins++;
  31.  
  32. // Increase step count for remaining
  33. for (int i = 0; i < n; ++i) {
  34. if (steps[i] >= 60) continue; // prevent overflow
  35. if (i != idx) steps[i]++;
  36. }
  37. }
  38.  
  39. cout << coins << endl;
  40. }
  41.  
  42. int32_t main() {
  43. fast_io;
  44. int t;
  45. cin >> t;
  46. while (t--) {
  47. solve();
  48. }
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.01s 5304KB
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
5
3
10
1