제출 #1327907

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

using namespace std;

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

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

void slv() {

    int n, m;
    cin >> n >> m;

    vector <int> 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];
    }

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

    while(l <= r) {
        int md = (l + r) / 2, cnt = 0;
        for(int i = 1; i <= n; i++) {
            int x = md;
            if(a[i] >= b[i]) {
                int y = min(m, x / a[i] + (x % a[i] != 0));
                cnt += y;
                x -= (a[i] * y);
            }
            if(x >= 0) {
                cnt += max(0LL, 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...