#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);
if (res < - M * N)
return false;
}
return res >= 0;
}
signed main () {
cin >> N >> M;
if (N < 0) {
N *= -1;
int a, b;
cin >> a >> b;
As.resize(N, a);
Bs.resize(N, b);
} else {
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 = 2e18;
while (b - a > 1) {
int c = (a + b) >> 1;
if (check(c)) a = c;
else b = c;
}
cout << a << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
197 ms |
4984 KB |
Output is correct |
12 |
Correct |
201 ms |
4984 KB |
Output is correct |
13 |
Correct |
183 ms |
4984 KB |
Output is correct |
14 |
Correct |
143 ms |
4980 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
71 ms |
6124 KB |
Output is correct |
17 |
Correct |
273 ms |
11364 KB |
Output is correct |
18 |
Correct |
205 ms |
10728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
71 ms |
6124 KB |
Output is correct |
3 |
Correct |
273 ms |
11364 KB |
Output is correct |
4 |
Correct |
205 ms |
10728 KB |
Output is correct |
5 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
101 ms |
2644 KB |
Output is correct |
14 |
Correct |
67 ms |
1748 KB |
Output is correct |
15 |
Correct |
53 ms |
1460 KB |
Output is correct |
16 |
Correct |
41 ms |
1236 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
6 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
197 ms |
4984 KB |
Output is correct |
12 |
Correct |
201 ms |
4984 KB |
Output is correct |
13 |
Correct |
183 ms |
4984 KB |
Output is correct |
14 |
Correct |
143 ms |
4980 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
101 ms |
2644 KB |
Output is correct |
24 |
Correct |
67 ms |
1748 KB |
Output is correct |
25 |
Correct |
53 ms |
1460 KB |
Output is correct |
26 |
Correct |
41 ms |
1236 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
464 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
71 ms |
6124 KB |
Output is correct |
36 |
Correct |
273 ms |
11364 KB |
Output is correct |
37 |
Correct |
205 ms |
10728 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
296 KB |
Output is correct |
45 |
Correct |
4 ms |
468 KB |
Output is correct |
46 |
Correct |
7 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
35 ms |
1992 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
4 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
121 ms |
5436 KB |
Output is correct |
56 |
Correct |
58 ms |
3252 KB |
Output is correct |
57 |
Correct |
49 ms |
3128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
101 ms |
2644 KB |
Output is correct |
10 |
Correct |
67 ms |
1748 KB |
Output is correct |
11 |
Correct |
53 ms |
1460 KB |
Output is correct |
12 |
Correct |
41 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
6 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
71 ms |
6124 KB |
Output is correct |
22 |
Correct |
273 ms |
11364 KB |
Output is correct |
23 |
Correct |
205 ms |
10728 KB |
Output is correct |
24 |
Correct |
50 ms |
1824 KB |
Output is correct |
25 |
Correct |
115 ms |
4992 KB |
Output is correct |
26 |
Correct |
23 ms |
1296 KB |
Output is correct |
27 |
Correct |
203 ms |
10776 KB |
Output is correct |
28 |
Correct |
209 ms |
10740 KB |
Output is correct |
29 |
Correct |
206 ms |
10700 KB |
Output is correct |
30 |
Correct |
237 ms |
10736 KB |
Output is correct |
31 |
Correct |
308 ms |
11004 KB |
Output is correct |
32 |
Correct |
138 ms |
6092 KB |
Output is correct |
33 |
Correct |
278 ms |
11432 KB |
Output is correct |
34 |
Correct |
132 ms |
6152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
197 ms |
4984 KB |
Output is correct |
12 |
Correct |
201 ms |
4984 KB |
Output is correct |
13 |
Correct |
183 ms |
4984 KB |
Output is correct |
14 |
Correct |
143 ms |
4980 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
101 ms |
2644 KB |
Output is correct |
24 |
Correct |
67 ms |
1748 KB |
Output is correct |
25 |
Correct |
53 ms |
1460 KB |
Output is correct |
26 |
Correct |
41 ms |
1236 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
464 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
296 KB |
Output is correct |
41 |
Correct |
4 ms |
468 KB |
Output is correct |
42 |
Correct |
7 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
35 ms |
1992 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
4 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
121 ms |
5436 KB |
Output is correct |
52 |
Correct |
58 ms |
3252 KB |
Output is correct |
53 |
Correct |
49 ms |
3128 KB |
Output is correct |
54 |
Correct |
50 ms |
1824 KB |
Output is correct |
55 |
Correct |
115 ms |
4992 KB |
Output is correct |
56 |
Correct |
23 ms |
1296 KB |
Output is correct |
57 |
Correct |
203 ms |
10776 KB |
Output is correct |
58 |
Correct |
209 ms |
10740 KB |
Output is correct |
59 |
Correct |
206 ms |
10700 KB |
Output is correct |
60 |
Correct |
237 ms |
10736 KB |
Output is correct |
61 |
Correct |
308 ms |
11004 KB |
Output is correct |
62 |
Correct |
138 ms |
6092 KB |
Output is correct |
63 |
Correct |
278 ms |
11432 KB |
Output is correct |
64 |
Correct |
132 ms |
6152 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
71 ms |
6124 KB |
Output is correct |
67 |
Correct |
273 ms |
11364 KB |
Output is correct |
68 |
Correct |
205 ms |
10728 KB |
Output is correct |
69 |
Correct |
31 ms |
1444 KB |
Output is correct |
70 |
Correct |
8 ms |
576 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
46 ms |
1744 KB |
Output is correct |
73 |
Correct |
10 ms |
596 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
206 ms |
10724 KB |
Output is correct |
76 |
Correct |
216 ms |
10788 KB |
Output is correct |
77 |
Correct |
226 ms |
10728 KB |
Output is correct |
78 |
Correct |
260 ms |
10700 KB |
Output is correct |
79 |
Correct |
310 ms |
10784 KB |
Output is correct |
80 |
Correct |
317 ms |
10784 KB |
Output is correct |
81 |
Correct |
221 ms |
8692 KB |
Output is correct |
82 |
Correct |
189 ms |
8680 KB |
Output is correct |