Submission #585234

# Submission time Handle Problem Language Result Execution time Memory
585234 2022-06-28T13:00:12 Z rgnerdplayer Self Study (JOI22_ho_t2) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    auto solve = [&]() {
        int n, m;
        cin >> n >> m;

        vector<int> a(n), b(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            cin >> b[i];
            a[i] = max(a[i], b[i]);
        }

        i64 lo = 0, hi = 2e18;

        while (lo < hi) {
            i64 md = lo + hi + 1 >> 1;
            i64 cnt = 0;
            bool ok = true;
            
            for (int i = 0; i < n; i++) {
                if (md <= 1LL * m * a[i]) {
                    cnt += (md + a[i] - 1) / a[i];
                } else {
                    cnt += m + (md - 1LL * a[i] * m + b[i] - 1) / b[i];
                }
                if (cnt > 1LL * n * m) {
                    ok = false;
                }
                break;
            }

            if (ok) {
                lo = md;
            } else {
                hi = md - 1;
            }
        }

        cout << lo << '\n';
    };
    
    solve();
    
    return 0;
}
 

Compilation message

Main.cpp: In lambda function:
Main.cpp:30:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |             i64 md = lo + hi + 1 >> 1;
      |                      ~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -