제출 #1184376

#제출 시각아이디문제언어결과실행 시간메모리
1184376bbartekSelf Study (JOI22_ho_t2)C++20
0 / 100
151 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;

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

    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 = 0, 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...