제출 #782296

#제출 시각아이디문제언어결과실행 시간메모리
782296TeaTimeSelf Study (JOI22_ho_t2)C++17
0 / 100
543 ms11608 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SZ = 200'100, LG = 18, INF = 1'000'000'000'000'000'100;

ll n, m;
vector<ll> vec1, vec2;

bool check(ll val) {
    vector<ll> vec;
    ll left = 0;
    for (int i = 0; i < n; i++) {
        ll needed = (val - 1) / vec1[i] + 1;

        if (needed <= m) {
            left += m - needed;
            vec.push_back(0);
        } else {
            vec.push_back(val - m * vec1[i]);
        }
    }

    for (int i = 0; i < n; i++) {
        if (vec[i] == 0) continue;

        left -= (vec[i] - 1) / vec2[i] + 1;
    }

    return left >= 0;
}

int main() {
    fastInp;

    cin >> n >> m;
    vec1.resize(n);
    vec2.resize(n);
    for (auto &c : vec1) cin >> c;
    for (auto &c : vec2) cin >> c;

    for (int i = 0; i < n; i++) {
        vec1[i] = max(vec1[i], vec2[i]);
    }

    ll l = 0, r = INF;

    while (r - l > 1) {
        ll mid = (l + r) / 2;

        if (check(mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }

    cout << l;

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