#include <bits/stdc++.h>
#define MAX 305000
using ll = long long;
__int128 A[MAX],B[MAX];
__int128 N,M;
__int128 teto(__int128 a,__int128 b){
ll c = a/b;
if(a%b)++c;
return c;
}
bool possivel(__int128 x){
__int128 sum=0;
for(int i=0;i!=N;++i){
__int128 necessario = teto(x,A[i]);
__int128 gastar = std::min(necessario,M);
__int128 falta = x-(gastar*A[i]);
if(falta>0){
ll precisa = teto(falta,B[i]);
sum-=precisa;
}else {
ll sobra = M-gastar;
sum+=sobra;
}
}
return sum>=0;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
ll a,b;
std::cin>>a>>b;N=a;M=b;
for(int i=0;i!=N;++i){long long x;std::cin>>x;A[i]=x;}
for(int i=0;i!=N;++i){long long x;std::cin>>x;B[i]=x;}
for(int i=0;i!=N;++i){
if(A[i]<B[i]){
A[i]=B[i];
}
}
__int128 l=1,r=1LL<<60LL;
while(l<r){
__int128 m=((r-l+1)/2)+l;
if(possivel(m)){
l=m;
}else r=m-1;
}
std::cout<<(ll)l<<"\n";
}
# |
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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
224 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
298 ms |
9704 KB |
Output is correct |
12 |
Correct |
284 ms |
9704 KB |
Output is correct |
13 |
Correct |
285 ms |
9828 KB |
Output is correct |
14 |
Correct |
317 ms |
9704 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
387 ms |
9704 KB |
Output is correct |
17 |
Correct |
307 ms |
9700 KB |
Output is correct |
18 |
Correct |
303 ms |
9704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
387 ms |
9704 KB |
Output is correct |
3 |
Correct |
307 ms |
9700 KB |
Output is correct |
4 |
Correct |
303 ms |
9704 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
147 ms |
5016 KB |
Output is correct |
14 |
Correct |
92 ms |
3448 KB |
Output is correct |
15 |
Correct |
69 ms |
2664 KB |
Output is correct |
16 |
Correct |
60 ms |
2208 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 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 |
6 ms |
468 KB |
Output is correct |
23 |
Correct |
5 ms |
468 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
224 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
298 ms |
9704 KB |
Output is correct |
12 |
Correct |
284 ms |
9704 KB |
Output is correct |
13 |
Correct |
285 ms |
9828 KB |
Output is correct |
14 |
Correct |
317 ms |
9704 KB |
Output is correct |
15 |
Correct |
0 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 |
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 |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
147 ms |
5016 KB |
Output is correct |
24 |
Correct |
92 ms |
3448 KB |
Output is correct |
25 |
Correct |
69 ms |
2664 KB |
Output is correct |
26 |
Correct |
60 ms |
2208 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 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 |
6 ms |
468 KB |
Output is correct |
33 |
Correct |
5 ms |
468 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
387 ms |
9704 KB |
Output is correct |
36 |
Correct |
307 ms |
9700 KB |
Output is correct |
37 |
Correct |
303 ms |
9704 KB |
Output is correct |
38 |
Correct |
1 ms |
328 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
6 ms |
468 KB |
Output is correct |
46 |
Correct |
13 ms |
720 KB |
Output is correct |
47 |
Correct |
2 ms |
340 KB |
Output is correct |
48 |
Correct |
54 ms |
2916 KB |
Output is correct |
49 |
Correct |
1 ms |
328 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
7 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
143 ms |
7844 KB |
Output is correct |
56 |
Correct |
102 ms |
4720 KB |
Output is correct |
57 |
Correct |
114 ms |
4720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
147 ms |
5016 KB |
Output is correct |
10 |
Correct |
92 ms |
3448 KB |
Output is correct |
11 |
Correct |
69 ms |
2664 KB |
Output is correct |
12 |
Correct |
60 ms |
2208 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 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 |
6 ms |
468 KB |
Output is correct |
19 |
Correct |
5 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
387 ms |
9704 KB |
Output is correct |
22 |
Correct |
307 ms |
9700 KB |
Output is correct |
23 |
Correct |
303 ms |
9704 KB |
Output is correct |
24 |
Correct |
41 ms |
2664 KB |
Output is correct |
25 |
Correct |
125 ms |
7116 KB |
Output is correct |
26 |
Correct |
38 ms |
1892 KB |
Output is correct |
27 |
Correct |
295 ms |
15504 KB |
Output is correct |
28 |
Correct |
326 ms |
15384 KB |
Output is correct |
29 |
Correct |
294 ms |
15504 KB |
Output is correct |
30 |
Correct |
304 ms |
15496 KB |
Output is correct |
31 |
Correct |
249 ms |
15504 KB |
Output is correct |
32 |
Correct |
354 ms |
10880 KB |
Output is correct |
33 |
Correct |
294 ms |
16056 KB |
Output is correct |
34 |
Correct |
370 ms |
10876 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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
224 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
298 ms |
9704 KB |
Output is correct |
12 |
Correct |
284 ms |
9704 KB |
Output is correct |
13 |
Correct |
285 ms |
9828 KB |
Output is correct |
14 |
Correct |
317 ms |
9704 KB |
Output is correct |
15 |
Correct |
0 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 |
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 |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
147 ms |
5016 KB |
Output is correct |
24 |
Correct |
92 ms |
3448 KB |
Output is correct |
25 |
Correct |
69 ms |
2664 KB |
Output is correct |
26 |
Correct |
60 ms |
2208 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 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 |
6 ms |
468 KB |
Output is correct |
33 |
Correct |
5 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
328 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
6 ms |
468 KB |
Output is correct |
42 |
Correct |
13 ms |
720 KB |
Output is correct |
43 |
Correct |
2 ms |
340 KB |
Output is correct |
44 |
Correct |
54 ms |
2916 KB |
Output is correct |
45 |
Correct |
1 ms |
328 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
7 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
143 ms |
7844 KB |
Output is correct |
52 |
Correct |
102 ms |
4720 KB |
Output is correct |
53 |
Correct |
114 ms |
4720 KB |
Output is correct |
54 |
Correct |
41 ms |
2664 KB |
Output is correct |
55 |
Correct |
125 ms |
7116 KB |
Output is correct |
56 |
Correct |
38 ms |
1892 KB |
Output is correct |
57 |
Correct |
295 ms |
15504 KB |
Output is correct |
58 |
Correct |
326 ms |
15384 KB |
Output is correct |
59 |
Correct |
294 ms |
15504 KB |
Output is correct |
60 |
Correct |
304 ms |
15496 KB |
Output is correct |
61 |
Correct |
249 ms |
15504 KB |
Output is correct |
62 |
Correct |
354 ms |
10880 KB |
Output is correct |
63 |
Correct |
294 ms |
16056 KB |
Output is correct |
64 |
Correct |
370 ms |
10876 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
387 ms |
9704 KB |
Output is correct |
67 |
Correct |
307 ms |
9700 KB |
Output is correct |
68 |
Correct |
303 ms |
9704 KB |
Output is correct |
69 |
Correct |
35 ms |
1896 KB |
Output is correct |
70 |
Correct |
9 ms |
724 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
42 ms |
2404 KB |
Output is correct |
73 |
Correct |
10 ms |
836 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
293 ms |
15500 KB |
Output is correct |
76 |
Correct |
338 ms |
15500 KB |
Output is correct |
77 |
Correct |
310 ms |
15412 KB |
Output is correct |
78 |
Correct |
298 ms |
15436 KB |
Output is correct |
79 |
Correct |
299 ms |
15500 KB |
Output is correct |
80 |
Correct |
296 ms |
15504 KB |
Output is correct |
81 |
Correct |
284 ms |
13520 KB |
Output is correct |
82 |
Correct |
285 ms |
13516 KB |
Output is correct |