fork download
  1.  
  2. #include<bits/stdc++.h>
  3. #define mod 1000000007
  4. #define pb push_back
  5. #define pop pop_back
  6. #define test unsigned long long int test; cin >> test; while(test--)
  7. #define show(x) cout<<(#x)<<"is"<<(x)<<"\n";
  8. typedef unsigned long long int ull;
  9. typedef long long int ll;
  10. using namespace std;
  11. int main(int argc, char const *argv[])
  12. {
  13. ios_base :: sync_with_stdio(false);
  14. cin.tie(NULL);
  15. test
  16. {
  17. ll n, z;
  18. cin >> n >> z;
  19. set<pair<int,int>> s;
  20. for (int i = 0; i < n; ++i)
  21. {
  22. ll k;
  23. cin >> k;
  24. s.insert(make_pair(k,i));
  25. }
  26. ll count=0,i=n;
  27. while (z>0)
  28. {
  29. auto it = --s.end();
  30. z = z - it->first;
  31. ll y = it->first;
  32. s.erase(it);
  33. y = y/2;
  34. s.insert(make_pair(y,i));
  35. count+=1;
  36. i+=1;
  37. }
  38. cout << count << endl;
  39. }
  40. return 0;
  41. }
Time limit exceeded #stdin #stdout 5s 644592KB
stdin
Standard input is empty
stdout
Standard output is empty