Submission #941212

#TimeUsernameProblemLanguageResultExecution timeMemory
941212peterandvoiSelf Study (JOI22_ho_t2)C++17
100 / 100
220 ms9172 KiB
#include <bits/stdc++.h>

using namespace std;

#ifdef ngu
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = (int) 3e5 + 5;

int n, m;
int a[N], b[N];

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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef ngu
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
    #endif
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin >> b[i];
    }
    long long l = 1, r = 1e18, res = 0;
    while (l <= r) {
        long long mid = l + r >> 1;
        if (check(mid)) {
            res = mid;
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }
    cout << res;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:51:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |         long long mid = l + r >> 1;
      |                         ~~^~~
#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...