#include <iostream>
#include <algorithm>
#define f first
#define s second
using namespace std;
long long n, m, a[300010], b[300010], ans;
__int128 l = 0, r = 1e20, mid, cnt, req;
bool check() {
cnt = req = 0;
for (int i = 1; i <= n; i++) {
if (b[i] > a[i]) {
cnt += m;
req += (mid+b[i]-1)/b[i];
} else {
if (a[i]*m >= mid) cnt += (a[i]*m-mid)/a[i];
else req += (mid-a[i]*m+b[i]-1)/b[i];
}
}
if (cnt < req) return 0;
else return 1;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
while (l <= r) {
mid = (l+r)/2;
if (!check()) r = mid-1;
else l = mid+1;
}
ans = r;
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
6 ms |
2396 KB |
Output is correct |
11 |
Correct |
337 ms |
9556 KB |
Output is correct |
12 |
Correct |
329 ms |
9716 KB |
Output is correct |
13 |
Correct |
237 ms |
8176 KB |
Output is correct |
14 |
Correct |
288 ms |
8092 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
257 ms |
6280 KB |
Output is correct |
17 |
Correct |
302 ms |
10340 KB |
Output is correct |
18 |
Correct |
314 ms |
9716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
257 ms |
6280 KB |
Output is correct |
3 |
Correct |
302 ms |
10340 KB |
Output is correct |
4 |
Correct |
314 ms |
9716 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2404 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2400 KB |
Output is correct |
10 |
Correct |
1 ms |
2400 KB |
Output is correct |
11 |
Correct |
1 ms |
2404 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
143 ms |
7264 KB |
Output is correct |
14 |
Correct |
97 ms |
6324 KB |
Output is correct |
15 |
Correct |
76 ms |
5968 KB |
Output is correct |
16 |
Correct |
60 ms |
5860 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
5 ms |
2396 KB |
Output is correct |
23 |
Correct |
5 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
6 ms |
2396 KB |
Output is correct |
11 |
Correct |
337 ms |
9556 KB |
Output is correct |
12 |
Correct |
329 ms |
9716 KB |
Output is correct |
13 |
Correct |
237 ms |
8176 KB |
Output is correct |
14 |
Correct |
288 ms |
8092 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2404 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2400 KB |
Output is correct |
20 |
Correct |
1 ms |
2400 KB |
Output is correct |
21 |
Correct |
1 ms |
2404 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
143 ms |
7264 KB |
Output is correct |
24 |
Correct |
97 ms |
6324 KB |
Output is correct |
25 |
Correct |
76 ms |
5968 KB |
Output is correct |
26 |
Correct |
60 ms |
5860 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
5 ms |
2396 KB |
Output is correct |
33 |
Correct |
5 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
257 ms |
6280 KB |
Output is correct |
36 |
Correct |
302 ms |
10340 KB |
Output is correct |
37 |
Correct |
314 ms |
9716 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
0 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2392 KB |
Output is correct |
45 |
Correct |
6 ms |
2592 KB |
Output is correct |
46 |
Correct |
10 ms |
2648 KB |
Output is correct |
47 |
Correct |
2 ms |
2504 KB |
Output is correct |
48 |
Correct |
58 ms |
5704 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
6 ms |
2396 KB |
Output is correct |
52 |
Correct |
1 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
54 |
Correct |
1 ms |
2396 KB |
Output is correct |
55 |
Correct |
182 ms |
7256 KB |
Output is correct |
56 |
Correct |
109 ms |
5972 KB |
Output is correct |
57 |
Correct |
130 ms |
5968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2404 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2400 KB |
Output is correct |
6 |
Correct |
1 ms |
2400 KB |
Output is correct |
7 |
Correct |
1 ms |
2404 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
143 ms |
7264 KB |
Output is correct |
10 |
Correct |
97 ms |
6324 KB |
Output is correct |
11 |
Correct |
76 ms |
5968 KB |
Output is correct |
12 |
Correct |
60 ms |
5860 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
5 ms |
2396 KB |
Output is correct |
19 |
Correct |
5 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
257 ms |
6280 KB |
Output is correct |
22 |
Correct |
302 ms |
10340 KB |
Output is correct |
23 |
Correct |
314 ms |
9716 KB |
Output is correct |
24 |
Correct |
51 ms |
5460 KB |
Output is correct |
25 |
Correct |
142 ms |
6992 KB |
Output is correct |
26 |
Correct |
35 ms |
5316 KB |
Output is correct |
27 |
Correct |
296 ms |
9716 KB |
Output is correct |
28 |
Correct |
289 ms |
9720 KB |
Output is correct |
29 |
Correct |
310 ms |
9492 KB |
Output is correct |
30 |
Correct |
302 ms |
9716 KB |
Output is correct |
31 |
Correct |
338 ms |
9812 KB |
Output is correct |
32 |
Correct |
252 ms |
6228 KB |
Output is correct |
33 |
Correct |
309 ms |
10488 KB |
Output is correct |
34 |
Correct |
257 ms |
6036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
6 ms |
2396 KB |
Output is correct |
11 |
Correct |
337 ms |
9556 KB |
Output is correct |
12 |
Correct |
329 ms |
9716 KB |
Output is correct |
13 |
Correct |
237 ms |
8176 KB |
Output is correct |
14 |
Correct |
288 ms |
8092 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2404 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2400 KB |
Output is correct |
20 |
Correct |
1 ms |
2400 KB |
Output is correct |
21 |
Correct |
1 ms |
2404 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
143 ms |
7264 KB |
Output is correct |
24 |
Correct |
97 ms |
6324 KB |
Output is correct |
25 |
Correct |
76 ms |
5968 KB |
Output is correct |
26 |
Correct |
60 ms |
5860 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
5 ms |
2396 KB |
Output is correct |
33 |
Correct |
5 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
0 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2392 KB |
Output is correct |
41 |
Correct |
6 ms |
2592 KB |
Output is correct |
42 |
Correct |
10 ms |
2648 KB |
Output is correct |
43 |
Correct |
2 ms |
2504 KB |
Output is correct |
44 |
Correct |
58 ms |
5704 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
6 ms |
2396 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
182 ms |
7256 KB |
Output is correct |
52 |
Correct |
109 ms |
5972 KB |
Output is correct |
53 |
Correct |
130 ms |
5968 KB |
Output is correct |
54 |
Correct |
51 ms |
5460 KB |
Output is correct |
55 |
Correct |
142 ms |
6992 KB |
Output is correct |
56 |
Correct |
35 ms |
5316 KB |
Output is correct |
57 |
Correct |
296 ms |
9716 KB |
Output is correct |
58 |
Correct |
289 ms |
9720 KB |
Output is correct |
59 |
Correct |
310 ms |
9492 KB |
Output is correct |
60 |
Correct |
302 ms |
9716 KB |
Output is correct |
61 |
Correct |
338 ms |
9812 KB |
Output is correct |
62 |
Correct |
252 ms |
6228 KB |
Output is correct |
63 |
Correct |
309 ms |
10488 KB |
Output is correct |
64 |
Correct |
257 ms |
6036 KB |
Output is correct |
65 |
Correct |
1 ms |
2396 KB |
Output is correct |
66 |
Correct |
257 ms |
6280 KB |
Output is correct |
67 |
Correct |
302 ms |
10340 KB |
Output is correct |
68 |
Correct |
314 ms |
9716 KB |
Output is correct |
69 |
Correct |
37 ms |
5328 KB |
Output is correct |
70 |
Correct |
11 ms |
2648 KB |
Output is correct |
71 |
Correct |
1 ms |
2392 KB |
Output is correct |
72 |
Correct |
50 ms |
5468 KB |
Output is correct |
73 |
Correct |
14 ms |
2652 KB |
Output is correct |
74 |
Correct |
2 ms |
2648 KB |
Output is correct |
75 |
Correct |
335 ms |
10664 KB |
Output is correct |
76 |
Correct |
331 ms |
11024 KB |
Output is correct |
77 |
Correct |
361 ms |
10904 KB |
Output is correct |
78 |
Correct |
340 ms |
11092 KB |
Output is correct |
79 |
Correct |
347 ms |
10904 KB |
Output is correct |
80 |
Correct |
340 ms |
10908 KB |
Output is correct |
81 |
Correct |
292 ms |
8788 KB |
Output is correct |
82 |
Correct |
304 ms |
8868 KB |
Output is correct |