#include <bits/stdc++.h>
using namespace std ;
const int MAX = 3e5 + 10 ;
int a[MAX] , b[MAX] ;
int n , m ;
bool check(long long x)
{
long long cnt = 0 ;
for(int i = 0 ; i < n ; ++i)
{
if(1ll * m * a[i] >= x)
cnt += m - (x + a[i] - 1ll) / a[i] ;
else
cnt -= (x - 1ll * m * a[i] + b[i] - 1ll) / b[i] ;
cnt = max(cnt , (long long)(-1ll * 1e18)) ;
}
return (cnt >= 0) ;
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>m ;
for(int i = 0 ; i < n ; ++i)
cin>>a[i] ;
for(int i = 0 ; i < n ; ++i)
cin>>b[i] ;
for(int i = 0 ; i < n ; ++i)
a[i] = max(a[i] , b[i]) ;
long long l = 0 , r = 1e18 ;
long long ans = l ;
while(l <= r)
{
long long mid = (l + r) >> 1ll ;
if(check(mid))
ans = mid , l = mid+1ll ;
else
r = mid-1ll ;
}
return cout<<ans<<"\n" , 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
143 ms |
2652 KB |
Output is correct |
12 |
Correct |
157 ms |
2648 KB |
Output is correct |
13 |
Correct |
134 ms |
2652 KB |
Output is correct |
14 |
Correct |
197 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
193 ms |
2652 KB |
Output is correct |
17 |
Correct |
146 ms |
2648 KB |
Output is correct |
18 |
Correct |
157 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
193 ms |
2652 KB |
Output is correct |
3 |
Correct |
146 ms |
2648 KB |
Output is correct |
4 |
Correct |
157 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
71 ms |
1492 KB |
Output is correct |
14 |
Correct |
56 ms |
1056 KB |
Output is correct |
15 |
Correct |
36 ms |
920 KB |
Output is correct |
16 |
Correct |
34 ms |
792 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
340 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 |
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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
143 ms |
2652 KB |
Output is correct |
12 |
Correct |
157 ms |
2648 KB |
Output is correct |
13 |
Correct |
134 ms |
2652 KB |
Output is correct |
14 |
Correct |
197 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
71 ms |
1492 KB |
Output is correct |
24 |
Correct |
56 ms |
1056 KB |
Output is correct |
25 |
Correct |
36 ms |
920 KB |
Output is correct |
26 |
Correct |
34 ms |
792 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
193 ms |
2652 KB |
Output is correct |
36 |
Correct |
146 ms |
2648 KB |
Output is correct |
37 |
Correct |
157 ms |
2648 KB |
Output is correct |
38 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
4 ms |
340 KB |
Output is correct |
46 |
Correct |
5 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
25 ms |
724 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
3 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
76 ms |
1424 KB |
Output is correct |
56 |
Correct |
45 ms |
1112 KB |
Output is correct |
57 |
Correct |
61 ms |
1044 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 |
1 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 |
71 ms |
1492 KB |
Output is correct |
10 |
Correct |
56 ms |
1056 KB |
Output is correct |
11 |
Correct |
36 ms |
920 KB |
Output is correct |
12 |
Correct |
34 ms |
792 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 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 |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
193 ms |
2652 KB |
Output is correct |
22 |
Correct |
146 ms |
2648 KB |
Output is correct |
23 |
Correct |
157 ms |
2648 KB |
Output is correct |
24 |
Correct |
29 ms |
692 KB |
Output is correct |
25 |
Correct |
80 ms |
3960 KB |
Output is correct |
26 |
Correct |
18 ms |
1164 KB |
Output is correct |
27 |
Correct |
155 ms |
8368 KB |
Output is correct |
28 |
Correct |
147 ms |
8448 KB |
Output is correct |
29 |
Correct |
154 ms |
8372 KB |
Output is correct |
30 |
Correct |
169 ms |
8452 KB |
Output is correct |
31 |
Correct |
200 ms |
8444 KB |
Output is correct |
32 |
Correct |
195 ms |
3824 KB |
Output is correct |
33 |
Correct |
220 ms |
9100 KB |
Output is correct |
34 |
Correct |
186 ms |
3828 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 |
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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
143 ms |
2652 KB |
Output is correct |
12 |
Correct |
157 ms |
2648 KB |
Output is correct |
13 |
Correct |
134 ms |
2652 KB |
Output is correct |
14 |
Correct |
197 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
71 ms |
1492 KB |
Output is correct |
24 |
Correct |
56 ms |
1056 KB |
Output is correct |
25 |
Correct |
36 ms |
920 KB |
Output is correct |
26 |
Correct |
34 ms |
792 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 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 |
4 ms |
340 KB |
Output is correct |
42 |
Correct |
5 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
25 ms |
724 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
3 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
76 ms |
1424 KB |
Output is correct |
52 |
Correct |
45 ms |
1112 KB |
Output is correct |
53 |
Correct |
61 ms |
1044 KB |
Output is correct |
54 |
Correct |
29 ms |
692 KB |
Output is correct |
55 |
Correct |
80 ms |
3960 KB |
Output is correct |
56 |
Correct |
18 ms |
1164 KB |
Output is correct |
57 |
Correct |
155 ms |
8368 KB |
Output is correct |
58 |
Correct |
147 ms |
8448 KB |
Output is correct |
59 |
Correct |
154 ms |
8372 KB |
Output is correct |
60 |
Correct |
169 ms |
8452 KB |
Output is correct |
61 |
Correct |
200 ms |
8444 KB |
Output is correct |
62 |
Correct |
195 ms |
3824 KB |
Output is correct |
63 |
Correct |
220 ms |
9100 KB |
Output is correct |
64 |
Correct |
186 ms |
3828 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
193 ms |
2652 KB |
Output is correct |
67 |
Correct |
146 ms |
2648 KB |
Output is correct |
68 |
Correct |
157 ms |
2648 KB |
Output is correct |
69 |
Correct |
22 ms |
1192 KB |
Output is correct |
70 |
Correct |
6 ms |
560 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
31 ms |
1412 KB |
Output is correct |
73 |
Correct |
7 ms |
540 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
162 ms |
8416 KB |
Output is correct |
76 |
Correct |
156 ms |
8412 KB |
Output is correct |
77 |
Correct |
161 ms |
8448 KB |
Output is correct |
78 |
Correct |
175 ms |
8444 KB |
Output is correct |
79 |
Correct |
201 ms |
8420 KB |
Output is correct |
80 |
Correct |
206 ms |
8392 KB |
Output is correct |
81 |
Correct |
203 ms |
6464 KB |
Output is correct |
82 |
Correct |
196 ms |
6464 KB |
Output is correct |