Submission #1320340

#TimeUsernameProblemLanguageResultExecution timeMemory
1320340aryanSelf Study (JOI22_ho_t2)C++17
0 / 100
189 ms5120 KiB
#include<bits/stdc++.h>
using namespace std;

using i64 = long long;


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

    int n;
    i64 m;
    cin >> n >> m;
    vector<i64> a(n);
    vector<i64> b(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    for(int i = 0;i < n;i++){
        cin >> b[i];
        a[i] = max(b[i],a[i]);
    }

    function<bool(i64)> f = [&](i64 x){
        i64 have = 0;
        for(int i = 0;i < n;i++){
            i64 tot = (x + a[i] - 1LL) / a[i];
            if(tot <= m){
                have += m - tot;
            }
        }
        for(int i = 0;i < n;i++){
            i64 tot = (x + a[i] - 1LL) / a[i];
            if(tot > m){
                i64 tx = x - m * a[i];
                assert(tx >= 0LL);
                tot = (tx + b[i] - 1LL) / b[i];
                have -= tot;
            }
        }
        return have >= 0LL;
    };

    i64 s = 0;
    i64 e = (i64)1e18 + 10LL;
    while(e > s){
        i64 mid = (e + s + 1) / 2LL;
        if(f(mid)){
            s = mid;
        }else{
            e = mid - 1LL;
        }
    }
    cout << e << '\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...