Submission #1011576

#TimeUsernameProblemLanguageResultExecution timeMemory
1011576AiperiiiSelf Study (JOI22_ho_t2)C++14
100 / 100
129 ms10892 KiB
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    vector <int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    int l=0,r=1e18+3000;
    
    while(l+1<r){
        int md=(l+r)/2;
        int tot=n*m;
        bool ok=1;
        for(int i=0;i<n;i++){
            if(a[i]<=b[i]){
                tot-=md/b[i];
                if(md%b[i]!=0){
                    tot--;
                }
                
                if(tot<0){
                    ok=0;break;
                }
                
            }
            else{
                int x=min(md/a[i],m);
                int y=md;
                y-=a[i]*x;
                tot-=x;
                if(tot<0){
                    ok=0;break;
                }
                if(y!=0){
                    if(x<m)tot--;
                    else{
                        tot-=y/b[i];
                        if(y%b[i]!=0)tot--;
                    }
                }
                if(tot<0){
                    ok=0;break;
                }
            }
        }
        if(ok)l=md;
        else r=md;
    }
    cout<<l<<"\n";
}
/*
 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...