#include<bits/stdc++.h>
#define int long long
#define pii pair<int, int>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int>a(n), b(n);
for (auto &i : a) cin >> i;
for (auto &i : b) cin >> i;
int l = -1, r = (long long)(1e18) + 5, mid;
cout << r << endl;
while (l + 1 < r) {
mid = (l + r) / 2;
int need = 0;
for (int i = 0 ; i < n ; i++) {
if (a[i] > b[i]) {
if (mid > a[i] * m) need += m + (mid - a[i] * m) / b[i] + ((mid - a[i] * m) % b[i] != 0ll ? 1ll : 0ll);
else need += (mid / a[i]) + (mid % a[i] != 0ll ? 1ll : 0ll);
} else {
need += (mid / b[i]) + (mid % b[i] != 0ll ? 1ll : 0ll);
}
}
if (need <= n * m) {
l = mid;
//cout << l << " " << need << "\n";
} else {
r = mid;
}
}
cout << l << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |