#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e5 + 10;
int a[N], b[N];
int n, m;
bool check(int x){
__int128_t remain = n * m;
for(int i = 0; i < n; i++){
__int128_t y = x;
if(b[i] > a[i]) a[i] = b[i];
__int128_t r1 = min((y + a[i] - 1) / a[i], (__int128_t) m);
remain -= r1;
y -= r1 * a[i];
__int128_t r2 = (y + b[i] - 1) / b[i];
if(r2 >= INT64_MAX) return false;
remain -= max((__int128_t) 0LL, r2);
}
return remain >= 0;
}
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 = 0, r = 1e18;
while(l != r){
if(check((l + r + 1) / 2)){
l = (l + r + 1) / 2;
}else{
r = (l + r + 1) / 2 - 1;
}
}
cout << l << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 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 |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
8 ms |
468 KB |
Output is correct |
11 |
Correct |
498 ms |
10824 KB |
Output is correct |
12 |
Correct |
531 ms |
10828 KB |
Output is correct |
13 |
Correct |
378 ms |
8796 KB |
Output is correct |
14 |
Correct |
436 ms |
8796 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
416 ms |
6148 KB |
Output is correct |
17 |
Correct |
469 ms |
11440 KB |
Output is correct |
18 |
Correct |
481 ms |
10832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
416 ms |
6148 KB |
Output is correct |
3 |
Correct |
469 ms |
11440 KB |
Output is correct |
4 |
Correct |
481 ms |
10832 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 |
220 KB |
Output is correct |
8 |
Correct |
1 ms |
220 KB |
Output is correct |
9 |
Correct |
1 ms |
228 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
232 ms |
5552 KB |
Output is correct |
14 |
Correct |
174 ms |
3792 KB |
Output is correct |
15 |
Correct |
119 ms |
2916 KB |
Output is correct |
16 |
Correct |
96 ms |
2336 KB |
Output is correct |
17 |
Correct |
2 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
312 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
7 ms |
400 KB |
Output is correct |
23 |
Correct |
8 ms |
444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 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 |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
8 ms |
468 KB |
Output is correct |
11 |
Correct |
498 ms |
10824 KB |
Output is correct |
12 |
Correct |
531 ms |
10828 KB |
Output is correct |
13 |
Correct |
378 ms |
8796 KB |
Output is correct |
14 |
Correct |
436 ms |
8796 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 |
220 KB |
Output is correct |
18 |
Correct |
1 ms |
220 KB |
Output is correct |
19 |
Correct |
1 ms |
228 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
232 ms |
5552 KB |
Output is correct |
24 |
Correct |
174 ms |
3792 KB |
Output is correct |
25 |
Correct |
119 ms |
2916 KB |
Output is correct |
26 |
Correct |
96 ms |
2336 KB |
Output is correct |
27 |
Correct |
2 ms |
324 KB |
Output is correct |
28 |
Correct |
1 ms |
312 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
312 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
7 ms |
400 KB |
Output is correct |
33 |
Correct |
8 ms |
444 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
416 ms |
6148 KB |
Output is correct |
36 |
Correct |
469 ms |
11440 KB |
Output is correct |
37 |
Correct |
481 ms |
10832 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 |
300 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
316 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
11 ms |
492 KB |
Output is correct |
46 |
Correct |
19 ms |
576 KB |
Output is correct |
47 |
Correct |
2 ms |
316 KB |
Output is correct |
48 |
Correct |
84 ms |
2092 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
9 ms |
468 KB |
Output is correct |
52 |
Correct |
0 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 |
249 ms |
5516 KB |
Output is correct |
56 |
Correct |
133 ms |
3128 KB |
Output is correct |
57 |
Correct |
153 ms |
3136 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 |
1 ms |
220 KB |
Output is correct |
4 |
Correct |
1 ms |
220 KB |
Output is correct |
5 |
Correct |
1 ms |
228 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
232 ms |
5552 KB |
Output is correct |
10 |
Correct |
174 ms |
3792 KB |
Output is correct |
11 |
Correct |
119 ms |
2916 KB |
Output is correct |
12 |
Correct |
96 ms |
2336 KB |
Output is correct |
13 |
Correct |
2 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
7 ms |
400 KB |
Output is correct |
19 |
Correct |
8 ms |
444 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
416 ms |
6148 KB |
Output is correct |
22 |
Correct |
469 ms |
11440 KB |
Output is correct |
23 |
Correct |
481 ms |
10832 KB |
Output is correct |
24 |
Correct |
78 ms |
1868 KB |
Output is correct |
25 |
Correct |
223 ms |
5080 KB |
Output is correct |
26 |
Correct |
48 ms |
1356 KB |
Output is correct |
27 |
Correct |
454 ms |
10788 KB |
Output is correct |
28 |
Correct |
489 ms |
10788 KB |
Output is correct |
29 |
Correct |
477 ms |
10852 KB |
Output is correct |
30 |
Correct |
474 ms |
10780 KB |
Output is correct |
31 |
Correct |
481 ms |
10692 KB |
Output is correct |
32 |
Correct |
426 ms |
6152 KB |
Output is correct |
33 |
Correct |
491 ms |
11504 KB |
Output is correct |
34 |
Correct |
452 ms |
6164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 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 |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
8 ms |
468 KB |
Output is correct |
11 |
Correct |
498 ms |
10824 KB |
Output is correct |
12 |
Correct |
531 ms |
10828 KB |
Output is correct |
13 |
Correct |
378 ms |
8796 KB |
Output is correct |
14 |
Correct |
436 ms |
8796 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 |
220 KB |
Output is correct |
18 |
Correct |
1 ms |
220 KB |
Output is correct |
19 |
Correct |
1 ms |
228 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
232 ms |
5552 KB |
Output is correct |
24 |
Correct |
174 ms |
3792 KB |
Output is correct |
25 |
Correct |
119 ms |
2916 KB |
Output is correct |
26 |
Correct |
96 ms |
2336 KB |
Output is correct |
27 |
Correct |
2 ms |
324 KB |
Output is correct |
28 |
Correct |
1 ms |
312 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
312 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
7 ms |
400 KB |
Output is correct |
33 |
Correct |
8 ms |
444 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 |
300 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
316 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
11 ms |
492 KB |
Output is correct |
42 |
Correct |
19 ms |
576 KB |
Output is correct |
43 |
Correct |
2 ms |
316 KB |
Output is correct |
44 |
Correct |
84 ms |
2092 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
9 ms |
468 KB |
Output is correct |
48 |
Correct |
0 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 |
249 ms |
5516 KB |
Output is correct |
52 |
Correct |
133 ms |
3128 KB |
Output is correct |
53 |
Correct |
153 ms |
3136 KB |
Output is correct |
54 |
Correct |
78 ms |
1868 KB |
Output is correct |
55 |
Correct |
223 ms |
5080 KB |
Output is correct |
56 |
Correct |
48 ms |
1356 KB |
Output is correct |
57 |
Correct |
454 ms |
10788 KB |
Output is correct |
58 |
Correct |
489 ms |
10788 KB |
Output is correct |
59 |
Correct |
477 ms |
10852 KB |
Output is correct |
60 |
Correct |
474 ms |
10780 KB |
Output is correct |
61 |
Correct |
481 ms |
10692 KB |
Output is correct |
62 |
Correct |
426 ms |
6152 KB |
Output is correct |
63 |
Correct |
491 ms |
11504 KB |
Output is correct |
64 |
Correct |
452 ms |
6164 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
416 ms |
6148 KB |
Output is correct |
67 |
Correct |
469 ms |
11440 KB |
Output is correct |
68 |
Correct |
481 ms |
10832 KB |
Output is correct |
69 |
Correct |
59 ms |
1320 KB |
Output is correct |
70 |
Correct |
15 ms |
552 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
84 ms |
1788 KB |
Output is correct |
73 |
Correct |
21 ms |
596 KB |
Output is correct |
74 |
Correct |
2 ms |
320 KB |
Output is correct |
75 |
Correct |
494 ms |
10784 KB |
Output is correct |
76 |
Correct |
503 ms |
10804 KB |
Output is correct |
77 |
Correct |
509 ms |
10848 KB |
Output is correct |
78 |
Correct |
538 ms |
10784 KB |
Output is correct |
79 |
Correct |
569 ms |
10896 KB |
Output is correct |
80 |
Correct |
574 ms |
10784 KB |
Output is correct |
81 |
Correct |
415 ms |
8912 KB |
Output is correct |
82 |
Correct |
481 ms |
8796 KB |
Output is correct |