#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 = 1e15 ;
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 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
120 ms |
8448 KB |
Output is correct |
12 |
Correct |
128 ms |
8444 KB |
Output is correct |
13 |
Correct |
109 ms |
6460 KB |
Output is correct |
14 |
Correct |
143 ms |
6464 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
143 ms |
3824 KB |
Output is correct |
17 |
Correct |
131 ms |
9112 KB |
Output is correct |
18 |
Correct |
145 ms |
8392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
143 ms |
3824 KB |
Output is correct |
3 |
Correct |
131 ms |
9112 KB |
Output is correct |
4 |
Correct |
145 ms |
8392 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 |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
70 ms |
4380 KB |
Output is correct |
14 |
Correct |
48 ms |
3028 KB |
Output is correct |
15 |
Correct |
31 ms |
2292 KB |
Output is correct |
16 |
Correct |
25 ms |
1944 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
252 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
372 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
120 ms |
8448 KB |
Output is correct |
12 |
Correct |
128 ms |
8444 KB |
Output is correct |
13 |
Correct |
109 ms |
6460 KB |
Output is correct |
14 |
Correct |
143 ms |
6464 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 |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
70 ms |
4380 KB |
Output is correct |
24 |
Correct |
48 ms |
3028 KB |
Output is correct |
25 |
Correct |
31 ms |
2292 KB |
Output is correct |
26 |
Correct |
25 ms |
1944 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
252 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
3 ms |
372 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
143 ms |
3824 KB |
Output is correct |
36 |
Correct |
131 ms |
9112 KB |
Output is correct |
37 |
Correct |
145 ms |
8392 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
328 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 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 |
2 ms |
436 KB |
Output is correct |
46 |
Correct |
4 ms |
576 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
21 ms |
1732 KB |
Output is correct |
49 |
Correct |
0 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
54 |
Correct |
0 ms |
328 KB |
Output is correct |
55 |
Correct |
71 ms |
4352 KB |
Output is correct |
56 |
Correct |
44 ms |
2372 KB |
Output is correct |
57 |
Correct |
49 ms |
2376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
70 ms |
4380 KB |
Output is correct |
10 |
Correct |
48 ms |
3028 KB |
Output is correct |
11 |
Correct |
31 ms |
2292 KB |
Output is correct |
12 |
Correct |
25 ms |
1944 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
252 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
372 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
143 ms |
3824 KB |
Output is correct |
22 |
Correct |
131 ms |
9112 KB |
Output is correct |
23 |
Correct |
145 ms |
8392 KB |
Output is correct |
24 |
Incorrect |
29 ms |
1572 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
120 ms |
8448 KB |
Output is correct |
12 |
Correct |
128 ms |
8444 KB |
Output is correct |
13 |
Correct |
109 ms |
6460 KB |
Output is correct |
14 |
Correct |
143 ms |
6464 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 |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
70 ms |
4380 KB |
Output is correct |
24 |
Correct |
48 ms |
3028 KB |
Output is correct |
25 |
Correct |
31 ms |
2292 KB |
Output is correct |
26 |
Correct |
25 ms |
1944 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
252 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
3 ms |
372 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
328 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 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 |
2 ms |
436 KB |
Output is correct |
42 |
Correct |
4 ms |
576 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
21 ms |
1732 KB |
Output is correct |
45 |
Correct |
0 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
0 ms |
328 KB |
Output is correct |
51 |
Correct |
71 ms |
4352 KB |
Output is correct |
52 |
Correct |
44 ms |
2372 KB |
Output is correct |
53 |
Correct |
49 ms |
2376 KB |
Output is correct |
54 |
Incorrect |
29 ms |
1572 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |