Submission #526869

#TimeUsernameProblemLanguageResultExecution timeMemory
526869eecsSelf Study (JOI22_ho_t2)C++17
100 / 100
297 ms9564 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 300010;
int n, m;
ll a[maxn], b[maxn];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &b[i]);
    }
    auto chk = [&](ll lim) {
        __int128 sum = 0;
        for (int i = 1; i <= n; i++) {
            ll rem = lim;
            if (a[i] > b[i]) {
                ll t = min(1LL * m, (lim + a[i] - 1) / a[i]);
                sum += t, rem -= t * a[i];
            }
            if (rem >= 0) sum += (rem + b[i] - 1) / b[i];
        }
        return sum <= 1LL * n * m;
    };
    ll l = 0, r = 1e18, ans;
    while (l <= r) {
        ll mid = (l + r) / 2;
        chk(mid) ? l = (ans = mid) + 1 : r = mid - 1;
    }
    printf("%lld\n", ans);
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%lld", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
Main.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%lld", &b[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
#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...