제출 #1332486

#제출 시각아이디문제언어결과실행 시간메모리
1332486BolatuluSelf Study (JOI22_ho_t2)C++20
0 / 100
95 ms7384 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define all(x) (x).begin(), (x).end()
#define md ((tl + tr) >> 1)
#define TL v + v, tl, md
#define TR v + v + 1, md + 1, tr
#define F first
#define S second
#define pii pair<int, int>
#define int ll

const int maxn = 3e5 + 7;
const ll inf = 1e18 + 7;
const double PI = atan2(0.0, -1.0);

int n, m, a[maxn], b[maxn], s[maxn];

bool check(int x) {
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (s[i] >= x)
            cnt += (s[i] - x) / a[i];
        else
            cnt -= (x - s[i] + b[i] - 1) / b[i];
    }
    return cnt >= 0;
}

void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> b[i];

    for (int i = 1; i <= n; i++) {
        a[i] = max(a[i], b[i]);
        s[i] = a[i] * m;
    }
    
    int l = 0, r = inf;
    while (l + 1 < r) {
        int mid = ((l + r) >> 1);
        if (check(mid))
            l = mid;
        else
            r = mid;
    }
    cout << l;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test = 1;
    // cin >> test;
    while (test--) {
        solve();
        // cout << '\n';
    }
    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...