#include<bits/stdc++.h>
#define int long long
#define pii pair<int, int>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int>a(n), b(n);
for (auto &i : a) cin >> i;
for (auto &i : b) cin >> i;
int l = -1, r = 1e18 + 5, mid;
while (l + 1 < r) {
mid = (l + r) / 2;
int need = 0;
for (int i = 0 ; i < n ; i++) {
if (a[i] > b[i]) {
if (mid > (__int128)a[i] * m) need += m + (mid - a[i] * m) / b[i] + ((mid - a[i] * m) % b[i] != 0ll ? 1ll : 0ll);
else need += (mid / a[i]) + (mid % a[i] != 0ll ? 1ll : 0ll);
} else {
need += (mid / b[i]) + (mid % b[i] != 0ll ? 1ll : 0ll);
}
if(need > n * m) break;
}
if (need <= n * m) {
l = mid;
//cout << l << " " << need << "\n";
} else {
r = mid;
}
}
cout << l << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
456 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
89 ms |
8088 KB |
Output is correct |
12 |
Correct |
86 ms |
8028 KB |
Output is correct |
13 |
Correct |
73 ms |
7408 KB |
Output is correct |
14 |
Correct |
67 ms |
7188 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
32 ms |
6168 KB |
Output is correct |
17 |
Correct |
81 ms |
11396 KB |
Output is correct |
18 |
Correct |
94 ms |
10884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
32 ms |
6168 KB |
Output is correct |
3 |
Correct |
81 ms |
11396 KB |
Output is correct |
4 |
Correct |
94 ms |
10884 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
43 ms |
4588 KB |
Output is correct |
14 |
Correct |
28 ms |
3156 KB |
Output is correct |
15 |
Correct |
20 ms |
2648 KB |
Output is correct |
16 |
Correct |
18 ms |
2136 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
448 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
456 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
89 ms |
8088 KB |
Output is correct |
12 |
Correct |
86 ms |
8028 KB |
Output is correct |
13 |
Correct |
73 ms |
7408 KB |
Output is correct |
14 |
Correct |
67 ms |
7188 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
43 ms |
4588 KB |
Output is correct |
24 |
Correct |
28 ms |
3156 KB |
Output is correct |
25 |
Correct |
20 ms |
2648 KB |
Output is correct |
26 |
Correct |
18 ms |
2136 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
448 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
32 ms |
6168 KB |
Output is correct |
36 |
Correct |
81 ms |
11396 KB |
Output is correct |
37 |
Correct |
94 ms |
10884 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
428 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
456 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
3 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
16 ms |
2140 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Correct |
1 ms |
344 KB |
Output is correct |
51 |
Correct |
2 ms |
604 KB |
Output is correct |
52 |
Correct |
0 ms |
344 KB |
Output is correct |
53 |
Correct |
0 ms |
452 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
47 ms |
5600 KB |
Output is correct |
56 |
Correct |
26 ms |
3304 KB |
Output is correct |
57 |
Correct |
20 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
43 ms |
4588 KB |
Output is correct |
10 |
Correct |
28 ms |
3156 KB |
Output is correct |
11 |
Correct |
20 ms |
2648 KB |
Output is correct |
12 |
Correct |
18 ms |
2136 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
448 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
32 ms |
6168 KB |
Output is correct |
22 |
Correct |
81 ms |
11396 KB |
Output is correct |
23 |
Correct |
94 ms |
10884 KB |
Output is correct |
24 |
Correct |
26 ms |
1884 KB |
Output is correct |
25 |
Correct |
63 ms |
4956 KB |
Output is correct |
26 |
Correct |
11 ms |
1624 KB |
Output is correct |
27 |
Correct |
82 ms |
10936 KB |
Output is correct |
28 |
Correct |
84 ms |
10756 KB |
Output is correct |
29 |
Correct |
93 ms |
10836 KB |
Output is correct |
30 |
Correct |
107 ms |
10884 KB |
Output is correct |
31 |
Correct |
179 ms |
10936 KB |
Output is correct |
32 |
Correct |
105 ms |
6312 KB |
Output is correct |
33 |
Incorrect |
215 ms |
11672 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
456 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
89 ms |
8088 KB |
Output is correct |
12 |
Correct |
86 ms |
8028 KB |
Output is correct |
13 |
Correct |
73 ms |
7408 KB |
Output is correct |
14 |
Correct |
67 ms |
7188 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
43 ms |
4588 KB |
Output is correct |
24 |
Correct |
28 ms |
3156 KB |
Output is correct |
25 |
Correct |
20 ms |
2648 KB |
Output is correct |
26 |
Correct |
18 ms |
2136 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
448 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
428 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
456 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
2 ms |
604 KB |
Output is correct |
42 |
Correct |
3 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
16 ms |
2140 KB |
Output is correct |
45 |
Correct |
0 ms |
344 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
2 ms |
604 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
0 ms |
452 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
47 ms |
5600 KB |
Output is correct |
52 |
Correct |
26 ms |
3304 KB |
Output is correct |
53 |
Correct |
20 ms |
3164 KB |
Output is correct |
54 |
Correct |
26 ms |
1884 KB |
Output is correct |
55 |
Correct |
63 ms |
4956 KB |
Output is correct |
56 |
Correct |
11 ms |
1624 KB |
Output is correct |
57 |
Correct |
82 ms |
10936 KB |
Output is correct |
58 |
Correct |
84 ms |
10756 KB |
Output is correct |
59 |
Correct |
93 ms |
10836 KB |
Output is correct |
60 |
Correct |
107 ms |
10884 KB |
Output is correct |
61 |
Correct |
179 ms |
10936 KB |
Output is correct |
62 |
Correct |
105 ms |
6312 KB |
Output is correct |
63 |
Incorrect |
215 ms |
11672 KB |
Output isn't correct |
64 |
Halted |
0 ms |
0 KB |
- |