Submission #526415

#TimeUsernameProblemLanguageResultExecution timeMemory
526415Jarif_RahmanSelf Study (JOI22_ho_t2)C++17
100 / 100
251 ms5060 KiB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

int n; ll m;
vector<ll> a, b;

bool check(ll X){
    __int128 e = 0;
    for(int i = 0; i < n; i++){
        ll c = m*a[i];
        if(c >= X){
            e+=m-((X+a[i]-1)/a[i]);
        }
        else{
            c = X-c;
            e-=(c+b[i]-1)/b[i];
        }
    }
    if(e >= 0) return 1;
    return 0;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    a.resize(n), b.resize(n);

    for(ll &x: a) cin >> x;
    for(ll &x: b) cin >> x;

    for(int i = 0; i < n; i++) a[i] = max(a[i], b[i]);

    ll a = 1, b = 2e18;
    while(a < b){
        ll md = (a+b+1)/2;
        if(check(md)) a = md;
        else b = md-1;
    }
    cout << a << "\n";
}
#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...