fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define eps 1e-9
  5. long double b[50005], h[50005], w[50005], d[50005];
  6. bool possible(ll n, long double wl, long double mid)
  7. {
  8. long double volume=0;
  9. for(ll i=0;i<n;i++)
  10. {
  11. if(b[i]<mid)
  12. {
  13. volume+=(min(mid-b[i], h[i])*d[i]*w[i]);
  14. }
  15. }
  16. if(volume+eps<wl)
  17. return true;
  18. return false;
  19. }
  20. int main()
  21. {
  22. ll t;
  23. cin>>t;
  24. while(t--)
  25. {
  26. ll n;
  27. cin>>n;
  28. for(ll i=0;i<n;i++)
  29. {
  30. cin>>b[i]>>h[i]>>w[i]>>d[i];
  31. }
  32. long double wl;
  33. cin>>wl;
  34. long double start=1, end=(4*(1e6)), ans=4*(1e6);
  35. while(fabs(start-end)>eps)
  36. {
  37.  
  38. long double mid=(start+end)/2;
  39. if(possible(n, wl, mid))
  40. {
  41. ans=mid;
  42. start=mid;
  43. }
  44. else
  45. {
  46. end=mid;
  47. }
  48. }
  49. if(start>3*(1e6))
  50. cout<<"OVERFLOW"<<endl;
  51. else
  52. printf("%0.2lF \n", start);
  53. }
  54. }
Time limit exceeded #stdin #stdout 5s 4280KB
stdin
Standard input is empty
stdout
Standard output is empty