Advertisement
pb_jiang

ABC389E WA

Jan 19th, 2025
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 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.             cost += x * cap * cap;
  28.         }
  29.         return cost <= m;
  30.     };
  31.     __int128 lb = 1, ub = m + 1;
  32.     while (lb + 1 < ub) {
  33.         __int128 mid = (lb + ub) / 2;
  34.         if (check(mid))
  35.             lb = mid;
  36.         else
  37.             ub = mid;
  38.     }
  39.     __int128 ans = 0;
  40.     for (auto x : ps) {
  41.         __int128 cap = (lb / x + 1) / 2;
  42.         ans += cap;
  43.         m -= cap * cap * x;
  44.     }
  45.     // ans += m / (lb + 1); // why?
  46.     cout << ll(ans) << '\n';
  47.     return 0;
  48. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement