#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;
| ~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |