fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. int32_t main()
  5. {
  6. int t;
  7. cin>>t;
  8. while(t--)
  9. {
  10. int n,a,b,x,y,z;
  11.  
  12.  
  13. cin>>n>>a>>b>>x>>y>>z;
  14. priority_queue<int>pq;
  15. for(int i=0;i<n;i++)
  16. {
  17. int temp;
  18. cin>>temp;
  19. pq.push(temp);
  20. }
  21. int temp=((z-b)/y);
  22.  
  23. if((float)((z-b)/(float)y)==(float)temp)
  24. temp--;
  25.  
  26. a=a+temp*x;
  27. int count=0;
  28. while(a<z && !pq.empty() && pq.top()!=0){
  29. a+=pq.top();
  30. int temp2=pq.top();
  31. pq.pop();
  32. pq.push(temp2/2);
  33. count++;
  34. }
  35. if(a>=z)
  36. cout<<count;
  37. else
  38. cout<<"RIP";
  39.  
  40. cout<<"\n";
  41.  
  42. }
  43.  
  44.  
  45. }
Success #stdin #stdout 0s 4416KB
stdin
3
3 10 15 5 10 100
12 15 18
3 10 15 5 10 100
5 5 10
4 40 80 30 30 100
100 100 100 100
stdout
4
RIP
1