제출 #879934

#제출 시각아이디문제언어결과실행 시간메모리
879934frostray8653Self Study (JOI22_ho_t2)C++17
100 / 100
388 ms11384 KiB
#include <bits/stdc++.h>
#define ll __int128_t
#define int long long
#define IO ios::sync_with_stdio(0), cin.tie(0)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
using namespace std;
using pii = pair<int, int>;
const int N = 300005;
const int INF = 2e18;
int n, m;
int a[N], b[N];

bool check(ll k) {
    ll cst_day = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] >= b[i]) {
            ll need = (k + a[i] - 1) / a[i];
            if (need > m) {
                ll less = k - m * a[i];
                cst_day += (less + b[i] - 1) / b[i];
            } else {
                cst_day -= m - need;
            }
        } else {
            ll need = (k + b[i] - 1) / b[i];
            if (need > m)
                cst_day += need - m;
            else
                cst_day -= m - need;
        }
    }
    return (cst_day <= 0);
}

signed main() {
    IO;
    cin >> n >> m;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) cin >> b[i];

    ll l = 0, r = 10000;
    while (check(r))
        r *= 2;
    while (l + 1 < r) {
        int mid = (l + r) >> 1;
        if (check(mid))
            l = mid;
        else
            r = mid;
    }
    int ans = l;
    cout << ans << "\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...