제출 #527528

#제출 시각아이디문제언어결과실행 시간메모리
527528voventaSelf Study (JOI22_ho_t2)C++17
100 / 100
258 ms9628 KiB
#include <bits/stdc++.h>
#define x first
#define y second
#define sz(a) (int)a.size()
#define pb push_back
#define int long long

using namespace std;
typedef long long ll;

void solve();

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}

int a[300010], b[300010];

int n, m;

int check(int x) {
    int cnt = m * n;
    for (int i = 0; i < n; ++i) {
        if (a[i] > b[i]) {
            int f = (x + a[i] - 1) / a[i];
            if (f <= m)
                cnt -= f;
            else {
                cnt -= m;
                cnt -= (x - a[i] * m + b[i] - 1) / b[i];
            }
        } else {
            cnt -= (x + b[i] - 1) / b[i];
        }
        if (cnt < 0)
            return false;
    }
    return true;
}

void solve() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
        cin >> b[i];
    int l = 0, r = 2e18;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (check(mid))
            l = mid;
        else
            r = mid;
    }
    cout << l << endl;

}
//923953850098595069
//890909762780980010

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