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