Advertisement
pb_jiang

ABC389E AC

Jan 19th, 2025
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #ifndef __DEBUG__
  5. #define dbg(...) 42
  6. #endif
  7. template <class T>
  8. using mpq = priority_queue<T, vector<T>, greater<T>>;
  9.  
  10. using ll = long long;
  11. using pii = pair<int, int>;
  12. using pll = pair<ll, ll>;
  13. using vl = vector<ll>;
  14. using vi = vector<int>;
  15.  
  16. int main(int argc, char **argv) {
  17.     ll n, m;
  18.     cin >> n >> m;
  19.     vl ps(n);
  20.     for (auto &x : ps)
  21.         cin >> x;
  22.     // ranges::sort(ps);
  23.     auto check = [&](__int128 s) -> bool {
  24.         __int128 cost = 0;
  25.         for (auto x : ps) {
  26.             __int128 cap = (s / x + 1) / 2;
  27.             if (cap && x * cap > m / cap)
  28.                 return false;
  29.             cost += x * cap * cap;
  30.         }
  31.         return cost <= m;
  32.     };
  33.     __int128 lb = 0, ub = m + 1;
  34.     while (lb + 1 < ub) {
  35.         __int128 mid = (lb + ub) / 2;
  36.         if (check(mid))
  37.             lb = mid;
  38.         else
  39.             ub = mid;
  40.     }
  41.     __int128 ans = 0;
  42.     for (auto x : ps) {
  43.         __int128 cap = (lb / x + 1) / 2;
  44.         ans += cap;
  45.         m -= cap * cap * x;
  46.     }
  47.     ans += m / (lb + 1);
  48.     cout << ll(ans) << '\n';
  49.     return 0;
  50. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement