#include <bits/stdc++.h>
#define int int64_t
using namespace std;
constexpr static int MXSIZE = 3e5;
int n, m, a[MXSIZE], b[MXSIZE], v[MXSIZE];
int ceil(int aa, int bb)
{
return (aa + bb-1) / bb;
}
int possible(int k)
{
for (int i = 0; i < n; i++)
v[i] = 0;
int r = n*m;
for (int i = 0; i < n; i++)
{
if (a[i] < b[i])
continue;
int s = min(ceil(k, a[i]), m);
v[i] = s * a[i];
r -= s;
}
for (int i = 0; i < n; i++)
{
if (k > v[i])
r -= ceil(k - v[i], b[i]);
if (r < 0)
return false;
}
return true;
}
int32_t main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int l = -1, r = 2e18;
while (r - l > 1)
{
int m = l+r>>1;
if (possible(m))
l = m;
else
r = m;
}
cout << l << "\n";
}
Compilation message
Main.cpp: In function 'int32_t main()':
Main.cpp:46:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | int m = l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
297 ms |
13096 KB |
Output is correct |
12 |
Correct |
293 ms |
13328 KB |
Output is correct |
13 |
Correct |
165 ms |
11044 KB |
Output is correct |
14 |
Correct |
224 ms |
11084 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
227 ms |
8556 KB |
Output is correct |
17 |
Correct |
282 ms |
13792 KB |
Output is correct |
18 |
Correct |
274 ms |
13060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
227 ms |
8556 KB |
Output is correct |
3 |
Correct |
282 ms |
13792 KB |
Output is correct |
4 |
Correct |
274 ms |
13060 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
312 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
139 ms |
6732 KB |
Output is correct |
14 |
Correct |
93 ms |
4492 KB |
Output is correct |
15 |
Correct |
72 ms |
3516 KB |
Output is correct |
16 |
Correct |
56 ms |
2864 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
4 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
297 ms |
13096 KB |
Output is correct |
12 |
Correct |
293 ms |
13328 KB |
Output is correct |
13 |
Correct |
165 ms |
11044 KB |
Output is correct |
14 |
Correct |
224 ms |
11084 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 |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
312 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
139 ms |
6732 KB |
Output is correct |
24 |
Correct |
93 ms |
4492 KB |
Output is correct |
25 |
Correct |
72 ms |
3516 KB |
Output is correct |
26 |
Correct |
56 ms |
2864 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
308 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
5 ms |
420 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
227 ms |
8556 KB |
Output is correct |
36 |
Correct |
282 ms |
13792 KB |
Output is correct |
37 |
Correct |
274 ms |
13060 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 |
308 KB |
Output is correct |
41 |
Correct |
0 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 |
212 KB |
Output is correct |
45 |
Correct |
6 ms |
596 KB |
Output is correct |
46 |
Correct |
9 ms |
700 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
51 ms |
2400 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
5 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
143 ms |
6660 KB |
Output is correct |
56 |
Correct |
57 ms |
3920 KB |
Output is correct |
57 |
Correct |
76 ms |
3928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
312 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 |
139 ms |
6732 KB |
Output is correct |
10 |
Correct |
93 ms |
4492 KB |
Output is correct |
11 |
Correct |
72 ms |
3516 KB |
Output is correct |
12 |
Correct |
56 ms |
2864 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
4 ms |
340 KB |
Output is correct |
19 |
Correct |
5 ms |
420 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
227 ms |
8556 KB |
Output is correct |
22 |
Correct |
282 ms |
13792 KB |
Output is correct |
23 |
Correct |
274 ms |
13060 KB |
Output is correct |
24 |
Correct |
50 ms |
2176 KB |
Output is correct |
25 |
Correct |
139 ms |
6048 KB |
Output is correct |
26 |
Correct |
30 ms |
1600 KB |
Output is correct |
27 |
Correct |
273 ms |
13132 KB |
Output is correct |
28 |
Correct |
280 ms |
13132 KB |
Output is correct |
29 |
Correct |
280 ms |
13136 KB |
Output is correct |
30 |
Correct |
294 ms |
13136 KB |
Output is correct |
31 |
Correct |
336 ms |
13128 KB |
Output is correct |
32 |
Correct |
253 ms |
8460 KB |
Output is correct |
33 |
Correct |
356 ms |
13784 KB |
Output is correct |
34 |
Correct |
272 ms |
8436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
297 ms |
13096 KB |
Output is correct |
12 |
Correct |
293 ms |
13328 KB |
Output is correct |
13 |
Correct |
165 ms |
11044 KB |
Output is correct |
14 |
Correct |
224 ms |
11084 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 |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
312 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
139 ms |
6732 KB |
Output is correct |
24 |
Correct |
93 ms |
4492 KB |
Output is correct |
25 |
Correct |
72 ms |
3516 KB |
Output is correct |
26 |
Correct |
56 ms |
2864 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
308 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
5 ms |
420 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
308 KB |
Output is correct |
37 |
Correct |
0 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 |
212 KB |
Output is correct |
41 |
Correct |
6 ms |
596 KB |
Output is correct |
42 |
Correct |
9 ms |
700 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
51 ms |
2400 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
5 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
143 ms |
6660 KB |
Output is correct |
52 |
Correct |
57 ms |
3920 KB |
Output is correct |
53 |
Correct |
76 ms |
3928 KB |
Output is correct |
54 |
Correct |
50 ms |
2176 KB |
Output is correct |
55 |
Correct |
139 ms |
6048 KB |
Output is correct |
56 |
Correct |
30 ms |
1600 KB |
Output is correct |
57 |
Correct |
273 ms |
13132 KB |
Output is correct |
58 |
Correct |
280 ms |
13132 KB |
Output is correct |
59 |
Correct |
280 ms |
13136 KB |
Output is correct |
60 |
Correct |
294 ms |
13136 KB |
Output is correct |
61 |
Correct |
336 ms |
13128 KB |
Output is correct |
62 |
Correct |
253 ms |
8460 KB |
Output is correct |
63 |
Correct |
356 ms |
13784 KB |
Output is correct |
64 |
Correct |
272 ms |
8436 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
227 ms |
8556 KB |
Output is correct |
67 |
Correct |
282 ms |
13792 KB |
Output is correct |
68 |
Correct |
274 ms |
13060 KB |
Output is correct |
69 |
Correct |
36 ms |
1620 KB |
Output is correct |
70 |
Correct |
9 ms |
596 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
48 ms |
2100 KB |
Output is correct |
73 |
Correct |
15 ms |
760 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
291 ms |
13128 KB |
Output is correct |
76 |
Correct |
320 ms |
13116 KB |
Output is correct |
77 |
Correct |
300 ms |
13076 KB |
Output is correct |
78 |
Correct |
313 ms |
13132 KB |
Output is correct |
79 |
Correct |
334 ms |
13228 KB |
Output is correct |
80 |
Correct |
366 ms |
13120 KB |
Output is correct |
81 |
Correct |
296 ms |
11144 KB |
Output is correct |
82 |
Correct |
284 ms |
11152 KB |
Output is correct |