# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1277602 | wedonttalkanymore | Self Study (JOI22_ho_t2) | C++20 | 136 ms | 5128 KiB |
#include <bits/stdc++.h>
/*
Brute to win
*/
using namespace std;
using ll = long long;
#define int long long
#define pii pair<ll, ll>
#define fi first
#define se second
const ll N = 3e5 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 19;
int n, m;
int a[N], b[N];
bool check(int mid) {
int sum = 0;
for (int i = 1; i <= n; i++) {
int val = max(a[i], b[i]);
int need = (mid + val - 1) / val;
if (need <= m) {
sum += need;
}
else {
int have = val * m;
int remain = mid - have;
int newneed = (remain + b[i] - 1) / b[i];
sum += newneed + m;
}
}
return sum <= n * m;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
if (fopen(".inp", "r")) {
freopen(".inp", "r", stdin);
freopen(".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];
int l = 1, r = 1e18, ans = 0;
while(l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout << ans;
return 0;
}
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... |