#include <bits/stdc++.h>
using namespace std;
#define int int64_t
int n, m;
bool check(int pos, vector<int>&a, vector<int>&b) {
int free = 0;
int req = 0;
for (int i=0; i<n; i++) {
int thisNeedsFromA = (pos+a[i]-1)/a[i];
if (thisNeedsFromA <= m) {
free += m-thisNeedsFromA;
}
else {
req += (pos-a[i]*m + b[i]-1)/b[i];
}
}
return free >= req;
}
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
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];
for (int i = 0; i<n; i++) a[i] = max(a[i], b[i]);
int l = 0, r = 1e18;
while (l < r) {
int pos = (l + r + 1) / 2;
if (check(pos, a, b)) {
l = pos;
} else {
r = pos-1;
}
}
cout << l << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
234 ms |
10896 KB |
Output is correct |
12 |
Correct |
232 ms |
10896 KB |
Output is correct |
13 |
Correct |
245 ms |
8832 KB |
Output is correct |
14 |
Incorrect |
481 ms |
8828 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
129 ms |
5564 KB |
Output is correct |
10 |
Correct |
80 ms |
3788 KB |
Output is correct |
11 |
Correct |
61 ms |
2904 KB |
Output is correct |
12 |
Correct |
48 ms |
2412 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Incorrect |
9 ms |
340 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
234 ms |
10896 KB |
Output is correct |
12 |
Correct |
232 ms |
10896 KB |
Output is correct |
13 |
Correct |
245 ms |
8832 KB |
Output is correct |
14 |
Incorrect |
481 ms |
8828 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
129 ms |
5564 KB |
Output is correct |
10 |
Correct |
80 ms |
3788 KB |
Output is correct |
11 |
Correct |
61 ms |
2904 KB |
Output is correct |
12 |
Correct |
48 ms |
2412 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Incorrect |
9 ms |
340 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
234 ms |
10896 KB |
Output is correct |
12 |
Correct |
232 ms |
10896 KB |
Output is correct |
13 |
Correct |
245 ms |
8832 KB |
Output is correct |
14 |
Incorrect |
481 ms |
8828 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |