#include <bits/stdc++.h>
#define int long long
using namespace std;
using idata = vector<int>;
int N, M;
idata As, Bs;
int ceilDiv (int x, int y) {
return (x + y - 1) / y;
}
int solve (int A, int B, int target) {
if (A < B) A = B;
if (A * M >= target)
return M - ceilDiv(target, A);
int local = target - A * M;
return - ceilDiv(local, B);
}
bool check (int target) {
int res = 0;
for (int i = 0; i < N; i ++)
res += solve(As[i], Bs[i], target);
return res >= 0;
}
signed main () {
cin >> N >> M;
As.resize(N); Bs.resize(N);
for (int i = 0; i < N; i ++) cin >> As[i];
for (int i = 0; i < N; i ++) cin >> Bs[i];
int a = 0;
int b = 1e16;
while (b - a > 1) {
int c = (a + b) >> 1;
if (check(c)) a = c;
else b = c;
}
cout << a << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
245 ms |
4980 KB |
Output is correct |
12 |
Correct |
251 ms |
4984 KB |
Output is correct |
13 |
Correct |
206 ms |
4984 KB |
Output is correct |
14 |
Incorrect |
337 ms |
4988 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
122 ms |
2644 KB |
Output is correct |
10 |
Correct |
80 ms |
1856 KB |
Output is correct |
11 |
Correct |
60 ms |
1364 KB |
Output is correct |
12 |
Correct |
48 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
245 ms |
4980 KB |
Output is correct |
12 |
Correct |
251 ms |
4984 KB |
Output is correct |
13 |
Correct |
206 ms |
4984 KB |
Output is correct |
14 |
Incorrect |
337 ms |
4988 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
122 ms |
2644 KB |
Output is correct |
10 |
Correct |
80 ms |
1856 KB |
Output is correct |
11 |
Correct |
60 ms |
1364 KB |
Output is correct |
12 |
Correct |
48 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
245 ms |
4980 KB |
Output is correct |
12 |
Correct |
251 ms |
4984 KB |
Output is correct |
13 |
Correct |
206 ms |
4984 KB |
Output is correct |
14 |
Incorrect |
337 ms |
4988 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |