#include <iostream>
#include <algorithm>
#define f first
#define s second
using namespace std;
long long n, m, a[300010], b[300010], l = 0, r = 9e18, mid, cnt, req;
bool check() {
cnt = req = 0;
for (int i = 1; i <= n; i++) {
if (b[i] > a[i]) {
cnt += m;
req += (mid+b[i]-1)/b[i];
} else {
if (a[i]*m >= mid) cnt += (a[i]*m-mid)/a[i];
else req += (mid-a[i]*m+b[i]-1)/b[i];
}
}
if (cnt < req) return 0;
else return 1;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
while (l <= r) {
mid = (l+r)/2;
if (!check()) r = mid-1;
else l = mid+1;
}
cout << r << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
5 ms |
2396 KB |
Output is correct |
11 |
Correct |
285 ms |
10904 KB |
Output is correct |
12 |
Correct |
276 ms |
10832 KB |
Output is correct |
13 |
Correct |
222 ms |
8784 KB |
Output is correct |
14 |
Incorrect |
360 ms |
8936 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
141 ms |
7448 KB |
Output is correct |
10 |
Correct |
90 ms |
6636 KB |
Output is correct |
11 |
Correct |
68 ms |
5980 KB |
Output is correct |
12 |
Correct |
54 ms |
5864 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Incorrect |
6 ms |
2396 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
5 ms |
2396 KB |
Output is correct |
11 |
Correct |
285 ms |
10904 KB |
Output is correct |
12 |
Correct |
276 ms |
10832 KB |
Output is correct |
13 |
Correct |
222 ms |
8784 KB |
Output is correct |
14 |
Incorrect |
360 ms |
8936 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
141 ms |
7448 KB |
Output is correct |
10 |
Correct |
90 ms |
6636 KB |
Output is correct |
11 |
Correct |
68 ms |
5980 KB |
Output is correct |
12 |
Correct |
54 ms |
5864 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Incorrect |
6 ms |
2396 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
5 ms |
2396 KB |
Output is correct |
11 |
Correct |
285 ms |
10904 KB |
Output is correct |
12 |
Correct |
276 ms |
10832 KB |
Output is correct |
13 |
Correct |
222 ms |
8784 KB |
Output is correct |
14 |
Incorrect |
360 ms |
8936 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |