Submission #1327908

#TimeUsernameProblemLanguageResultExecution timeMemory
1327908MuhammetSelf Study (JOI22_ho_t2)C++20
100 / 100
136 ms5120 KiB
#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define ll long long
#define SZ(s) (int)s.size()

const int N = 1e6 + 5;
const int M = 100000;

void slv() {

    ll n, m;
    cin >> n >> m;

    vector <ll> a(n+1), b(n+1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++) {
        cin >> b[i];
    }

    ll l = 1, r = 1e18, k = 0;

    while(l <= r) {
        ll md = (l + r) / 2, cnt = 0;
        for(int i = 1; i <= n; i++) {
            ll x = md;
            if(a[i] >= b[i]) {
                ll y = min(m, (x / a[i]) + (x % a[i] != 0));
                if(cnt + y > n * m) {
                    cnt = n * m + 1;
                    break;
                }
                cnt += y;
                x -= (a[i] * y);
            }
            if(x > 0) {
                if(cnt + ((x / b[i]) + (x % b[i] != 0)) > n * m) {
                    cnt = n * m + 1;
                    break;
                }
                cnt += ((x / b[i]) + (x % b[i] != 0));
            }
        }
        if(cnt <= n * m) {
            l = md+1LL;
            k = md;
        }
        else {
            r = md-1LL;
        }
    }

    cout << k << '\n';

    return;
}

signed main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    while(T--) slv();

    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...