Submission #1315161

#TimeUsernameProblemLanguageResultExecution timeMemory
1315161nathako9nSelf Study (JOI22_ho_t2)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int N = 300005;
ll a[N+2],b[N+3];
ll n,m;
bool ch(ll mid){
    ll nd=0,gv=0;
    for(int i=1;i<=n;i++){
        if(b[i]>=a[i]){
            ll wan=ceil(float(mid)/b[i]);
            if(wan==0)wan++;
            if(wan>m){
                nd+=wan-m;
            }
            else gv+=m-wan;
        }
        else{
           ll wan=ceil(float(mid)/a[i]);
            if(wan==0)wan++;
            if(wan>m){
                nd+=wan-m;
            }
            else gv+=m-wan;
        }
    }
    return gv>=nd;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    for(int i=0;i<=1;i++){
        for(int j=1;j<=n;j++){
            if(i)cin>>b[i];
            else cin>>a[i];
        }
    }
    ll r= 1e16,l=1;
    while(l<=r){
        ll mid=l+(r-l)/2;
        if(ch(mid))l=mid+1;
        else r=mid-1;
    }
    cout<<r;
//ll c=ceil(float(18)/5)*(5);cout<<c;
}

/*

3 3
19 4 5
2 6 2

*/

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