Submission #1267765

#TimeUsernameProblemLanguageResultExecution timeMemory
1267765gustavo_dSelf Study (JOI22_ho_t2)C++20
100 / 100
110 ms5132 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAXN = 3e5;
const ll INF = 1e18;

ll a[MAXN], b[MAXN];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int n; ll days; cin >> n >> days;
    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; ll ans = 0;
    while (l <= r) {
        ll mid = (l + r) / 2;

        ll available = 0, needed = 0;
        for (int i=0; i<n; i++) {
            ll val = max(a[i], b[i]);
            ll need = (mid + val - 1) / val;
            if (need <= days) available += days - need;
            else needed += (mid - days * val + b[i] - 1) / b[i];
            if (needed > n * days) break;
        }

        if (available >= needed) {
            ans = mid;
            l = mid+1;
        } else r = mid-1;
    }
    cout << ans << '\n';

    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...