fork download
  1. #include <iostream>
  2. #include<queue>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. int t;
  8. cin >> t;
  9. while(t--){
  10. int n,i;
  11. long int a,b,x,y,z;
  12. cin>>n>>a>>b>>x>>y>>z;
  13. priority_queue<long int> c;
  14. long int q;
  15. for(i =0; i<n;i++){
  16. cin>>q;
  17. c.push(q);
  18. }
  19. long int prem = (z-a)%x;
  20. long int hday = (z-b)/y;
  21. if((z-b)%y != 0)
  22. hday++;
  23. prem = z - (a+((hday-1)*x));
  24. // printf("%ld\n",prem);
  25. int flg = 0,cnt = 0;
  26. while(prem > 0 && c.size() > 0){
  27. q = c.top();
  28. c.pop();
  29. //printf("%ld\n",q);
  30. prem -= q;
  31. cnt++;
  32. long int tmp = q >> 1;
  33. if(tmp > 0)
  34. c.push(tmp);
  35. }
  36. if(prem > 0){
  37. printf("RIP\n");
  38. }
  39. else
  40. printf("%d\n",cnt);
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0s 4520KB
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