Submission #593559

#TimeUsernameProblemLanguageResultExecution timeMemory
593559piOOESelf Study (JOI22_ho_t2)C++17
0 / 100
515 ms5392 KiB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    const ll inf = 3e18;
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    ll L = 0, R = inf;
    while (L + 1 < R) {
        ll mid = (L + R) >> 1;
        auto check = [&]() -> bool {
            ll cnt = n * (ll)m;
            for (int i = 0; i < n; ++i) {
                if (b[i] >= a[i]) {
                    ll now = (mid + b[i] - 1) / b[i];
                    cnt -= now;
                } else {
                    ll now = (mid + a[i] - 1) / a[i];
                    if (now <= m) {
                        cnt -= now;
                    } else {
                        ll whole = m + (mid - a[i] * m + b[i] - 1) / b[i];
                        cnt -= whole;
                    }
                }
            }
            return cnt >= 0;
        };
        if (check()) {
            L = mid;
        } else {
            R = mid;
        }
    }
    cout << L;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...