Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T>
- using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- using vi = vector<int>;
- int main(int argc, char **argv) {
- ll n, m;
- cin >> n >> m;
- vl ps(n);
- for (auto &x : ps)
- cin >> x;
- // ranges::sort(ps);
- auto check = [&](__int128 s) -> bool {
- __int128 cost = 0;
- for (auto x : ps) {
- __int128 cap = (s / x + 1) / 2;
- cost += x * cap * cap;
- }
- return cost <= m;
- };
- __int128 lb = 1, ub = m + 1;
- while (lb + 1 < ub) {
- __int128 mid = (lb + ub) / 2;
- if (check(mid))
- lb = mid;
- else
- ub = mid;
- }
- __int128 ans = 0;
- for (auto x : ps) {
- __int128 cap = (lb / x + 1) / 2;
- ans += cap;
- m -= cap * cap * x;
- }
- // ans += m / (lb + 1); // why?
- cout << ll(ans) << '\n';
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement