Submission #1271634

#TimeUsernameProblemLanguageResultExecution timeMemory
1271634SofiatpcSelf Study (JOI22_ho_t2)C++20
0 / 100
94 ms5028 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long
const int MAXN = 3*1e5+5;
int a[MAXN], b[MAXN], n,m;

int teto(int x, int y){
    return (x + (y-1))/y;
}

bool test(int h){
    int tempo = 0;
    for(int i = 1; i <= n; i++){
        if(max(a[i],b[i])*m >= h){
            tempo += teto(h, max(a[i],b[i]) );
        }
        else{
            tempo += m + teto( h - max(a[i],b[i])*m, b[i]);
        }
    }  
    return tempo <= n*m;
}

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

    cin>>n>>m;
    for(int i = 1; i <= n; i++)cin>>a[i];
    for(int i = 1; i <= n; i++)cin>>b[i];

    int l = 0, r = 1e18;
    while(l != r){
        int mid = (l+r+1)/2;
        if(test(mid)) l = mid;
        else r = mid-1;
    }
    cout<<l<<"\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...