Submission #938551

#TimeUsernameProblemLanguageResultExecution timeMemory
938551the_coding_poohSelf Study (JOI22_ho_t2)C++14
100 / 100
236 ms13904 KiB
#include <bits/stdc++.h>
#define uwu return 0;

using namespace std;

#define fs first
#define sc second

#define int long long

using ll = long long;

const ll SIZE = 3e5 + 5;

const long long INF = 2e18 + 5;

ll N;
ll M;

ll A[SIZE], B[SIZE], rm[SIZE];

bool eval(ll mn){
    //cout << mn << '\n';
    ll left_h = 0;
    for (int i = 0; i < N;i++){
        rm[i] = mn;
        if((mn - 1LL) / A[i] + 1 < M){
            rm[i] = 0LL;
            left_h += M - ((mn - 1LL) / A[i] + 1LL);
        }
        else{
            rm[i] -= M * A[i];
        }
        //cout << rm[i] << ' ';
    }
    //cout << left_h << '\n';
    for (int i = 0; i < N;i++){
        if(rm[i] <= 0LL) continue; 
        if(left_h < (rm[i] - 1) / B[i] + 1){
            return false;
        }
        left_h -= ((rm[i] - 1LL) / B[i] + 1LL);
    }
    return true;
}

signed main(){
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> N >> M;

    for (int i = 0; i < N;i++){
        cin >> A[i];
    }

    for (int i = 0; i < N;i++){
        cin >> B[i];
        if(B[i] > A[i])
            A[i] = B[i];
    }

    ll L = 0, R = INF, m;

    while(L < R){
        m = (L + R + 1LL) >> 1;
        if(eval(m))
            L = m;
        else
            R = m - 1LL;
    }
    
    cout << L << '\n';
    uwu
}
#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...