Dang_Quan_10_Tin

FILL

Dec 4th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <iomanip>
  4. #define task "FILL"
  5. using namespace std;
  6. using ll = long long;
  7. using ld = long double;
  8. using ull = unsigned long long;
  9.  
  10. const int N = 1e5 + 2;
  11. const ld eps = 1e-3;
  12. int n, t;
  13. ll V;
  14. struct Jar
  15. {
  16.     int h, b, w, d;
  17. } a[N];
  18.  
  19. void Read()
  20. {
  21.     cin >> n >> V;
  22.     for (int i = 1; i <= n; ++i)
  23.         cin >> a[i].h >> a[i].b >> a[i].w >> a[i].d;
  24.     cin >> t;
  25. }
  26.  
  27. bool Check(ld v)
  28. {
  29.     ld ans = 0;
  30.     for (int i = 1; i <= n; ++i)
  31.     {
  32.         if (v >= a[i].h)
  33.         {
  34.             ans += (ld)1.0 * a[i].w * a[i].d * min(v - a[i].h, (ld)a[i].b);
  35.             if (ans >= (ld)V - eps)
  36.                 return true;
  37.         }
  38.     }
  39.     return false;
  40. }
  41.  
  42. void Solve()
  43. {
  44.     ld l = 0, m, h = 1e18;
  45.     while (h - l >= eps)
  46.     {
  47.         m = (l + h) / 2;
  48.         if (Check(m))
  49.             h = m;
  50.         else
  51.             l = m;
  52.     }
  53.     cout << fixed << setprecision(2) << h;
  54. }
  55.  
  56. int32_t main()
  57. {
  58.     ios_base::sync_with_stdio(0);
  59.     cin.tie(0);
  60.     cout.tie(0);
  61.     if (fopen(task ".INP", "r"))
  62.     {
  63.         freopen(task ".INP", "r", stdin);
  64.         freopen(task ".OUT", "w", stdout);
  65.     }
  66.     Read();
  67.     Solve();
  68. }
  69.  
Add Comment
Please, Sign In to add comment