# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1147865 | mingga | Self Study (JOI22_ho_t2) | C++20 | 87 ms | 5064 KiB |
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 3e5 + 7;
int n, m, a[N], b[N];
bool check(int mid) {
int cnt = 0;
for(int i = 1; i <= n; i++) {
if(a[i] * m >= mid) {
cnt += (a[i] * m - mid) / a[i];
} else {
cnt -= (mid - a[i] * m + b[i] - 1) / b[i];
if(cnt < -inf) cnt = -inf;
}
}
return cnt >= 0;
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i], a[i] = max(a[i], b[i]);
int l = 0, r = 1e18, ans = 0;
while(l <= r) {
int m = (l + r) >> 1;
if(check(m)) {
ans = m;
l = m + 1;
} else r = m - 1;
}
cout << ans << ln;
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |