Submission #1144148

#TimeUsernameProblemLanguageResultExecution timeMemory
1144148Aryan_RainaSelf Study (JOI22_ho_t2)C++20
0 / 100
144 ms4936 KiB
#include <bits/stdc++.h>

using namespace std;

#define int int64_t
#define ar array
#define all(v) begin(v), end(v)
#define allr(v) rbegin(v), rend(v)
#define pb push_back

const int INF = 1e10;

void solve() {  
    int n, m; cin >> n >> m;
    vector<int> a(n), b(n);
    for (int &x : a) cin >> x;
    for (int &x : b) cin >> x;
    for (int i = 0; i < n; i++) a[i] = max(a[i], b[i]);


    auto joke = [&](int ans) {
        int excess = 0;
        for (int i = 0; i < n; i++) excess += max(0L, (a[i]*m - ans) / a[i]);
        for (int i = 0; i < n; i++) excess -= max(0L, (ans - a[i]*m + b[i] - 1) / b[i]);
        //cout << excess << ' ' << ans << '\n';
        return excess >= 0;
    };

    int l = 0, r = 3e18+1;
    while (r-l > 1) {
        int mid = l + (r-l)/2;
        if (joke(mid)) l = mid;
        else r = mid;
    }

    cout << l << '\n';
}   

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1; //cin >> t;
    while (t--) {
        solve();
    }
}
#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...