제출 #1184415

#제출 시각아이디문제언어결과실행 시간메모리
1184415bbartekSelf Study (JOI22_ho_t2)C++20
100 / 100
137 ms5136 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define st first
#define nd second
#define pb push_back

const int maxn = 3e5+7;

ll A[maxn];
ll B[maxn];

ll n,m;

ll sufit(ll a,ll b){
    ll wyn = a/b + 1;
    if(a%b == 0)
        wyn--;
    return wyn;
}

bool czyok(ll x){
    ll suma = 0,ile,akt;
    for(int i=1;i<=n;i++){
        ile = sufit(x,A[i]);
        if(ile <= m){
            suma += ile;
        }
        else{
            akt = x - m*A[i];
            suma += m + sufit(akt,B[i]);
        }
        if(suma > 1e18)
            return 0;
    }

    if(suma <= n*m)
        return 1;
    return 0;
}

int 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];
        A[i] = max(A[i],B[i]);
    }

    ll pocz = 1, kon = 1e18+7, sro;

    while(pocz < kon){
        sro = (pocz+kon+1)/2;
        if(czyok(sro)){
            pocz = sro;
        }
        else{
            kon = sro-1;
        }
    }

    cout<<pocz<<"\n";
    
    return 0;
}
#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...