제출 #1339564

#제출 시각아이디문제언어결과실행 시간메모리
1339564ninstroyerSelf Study (JOI22_ho_t2)C++20
100 / 100
137 ms5128 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long

const ll nx = 3e5+5;

ll n,m,a[nx],b[nx];

bool check(ll x)
{
    ll timeLeft = n*m;
    for(int i = 1; i <= n; i++)
    {
        if(timeLeft < 0) return false;
        ll total = 0;
        if(a[i]>b[i])
        {
            ll cnt = x/a[i] + (x%a[i]!=0);
            total += min(cnt*a[i],m*a[i]);
            timeLeft -= min(m,cnt);
        }
        if(total>=x) continue;
        ll cnt = (x-total)/b[i] + ((x-total)%b[i]!=0);
        timeLeft -= cnt;
    }
    return timeLeft >= 0;
}

int main()
{
    ios::sync_with_stdio(false); 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];
    ll l = 0, r = 1e18+5;
    while(l<r)
    {
        ll md = (l+r+1)/2;
        if(check(md)) l = md;
        else r = md-1;
    }
    cout<<l;
}
#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...