fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n;
  5. vector<pair<pair<long double,long double>,pair<long double,long double> > > v;
  6. long double low,high;
  7. long double V;
  8.  
  9. void f(){
  10. while(high-low > 1e-8){
  11. long double m = (low+high)/2.0;
  12. long double volume=0;
  13. for(int i=0;i<n;i++){
  14. if(m>v[i].first.first){
  15. if(m>=(v[i].first.first + v[i].first.second)){
  16. volume += ((v[i].first.second) * (v[i].second.first) * (v[i].second.second));
  17. }else{
  18. volume += ((m - v[i].first.first) * (v[i].second.first) * (v[i].second.second));
  19. }
  20. }
  21. }
  22. if(volume<V){low=m;}
  23. else{high=m;}
  24. }
  25. printf("%.2LF\n",low);
  26. }
  27.  
  28. int main(){
  29. #ifndef ONLINE_JUDGE
  30. freopen("input.in","r",stdin);
  31. freopen("output.out","w",stdout);
  32. #endif
  33.  
  34. int t;
  35. cin>>t;
  36.  
  37. while(t--){
  38. v.clear();
  39. cin>>n;
  40.  
  41. low = 100000000,high = -100000000;
  42. long double TV=0;
  43. for(int i=0;i<n;i++){
  44. long double a,b,c,d;
  45. cin>>a>>b>>c>>d;
  46.  
  47. v.push_back(make_pair(make_pair(a,b),make_pair(c,d)));
  48. if(low>(a+b)){low=a+b;}
  49. if(high<(a+b)){high=a+b;}
  50. TV += (b*c*d);
  51. }
  52. cin>>V;
  53. //cout<<TV<<" "<<V<<endl;
  54. if(TV < V){cout<<"OVERFLOW"<<endl;}
  55. else{
  56. f();
  57. }
  58. }
  59. }
Success #stdin #stdout 0s 15240KB
stdin
3 
2 
0 1 1 1 
2 1 1 1 
1 
4 
11 7 5 1 
15 6 2 2 
5 8 5 1 
19 4 8 1 
132 
4 
11 7 5 1 
15 6 2 2 
5 8 5 1 
19 4 8 1 
78 
stdout
1.00
OVERFLOW
17.00