#include<bits/stdc++.h>
using namespace std;
#define int __int128
int n;int m;
int ar[300005];
int br[300005];
int cr[300005];
int ok(int mi){
int lft=0;
for(int i=1;i<=n;i++){
int nd=(mi+ar[i]-1)/ar[i];
if(nd<=m){
cr[i]=0;
lft+=m-nd;
}else{
cr[i]=mi-ar[i]*m;
}
}
for(int i=1;i<=n;i++){
if(cr[i]==0){continue;}
lft-=(cr[i]+br[i]-1)/br[i];
}
if(lft>=0){return 1;}
return 0;
}
int read(){
long long ret;
cin>>ret;
return ret;
}
signed main(){
//cin>>n>>m;
n=read();m=read();
for(int i=1;i<=n;i++){
ar[i]=read();
}
for(int i=1;i<=n;i++){
br[i]=read();
ar[i]=max(ar[i],br[i]);
}
int l=1;int r=1e18;
while(l<r){
int mi=l+(r-l+1)/2;
if(ok(mi)){
l=mi;
}else{
r=mi-1;
}
}
long long t=l;
cout<<t<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
10 ms |
596 KB |
Output is correct |
11 |
Correct |
438 ms |
14624 KB |
Output is correct |
12 |
Correct |
444 ms |
14748 KB |
Output is correct |
13 |
Correct |
368 ms |
14636 KB |
Output is correct |
14 |
Correct |
441 ms |
14672 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
454 ms |
15460 KB |
Output is correct |
17 |
Correct |
472 ms |
15552 KB |
Output is correct |
18 |
Correct |
471 ms |
15516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
454 ms |
15460 KB |
Output is correct |
3 |
Correct |
472 ms |
15552 KB |
Output is correct |
4 |
Correct |
471 ms |
15516 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 |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
219 ms |
7604 KB |
Output is correct |
14 |
Correct |
156 ms |
5196 KB |
Output is correct |
15 |
Correct |
104 ms |
4056 KB |
Output is correct |
16 |
Correct |
95 ms |
3348 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 |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
8 ms |
468 KB |
Output is correct |
23 |
Correct |
8 ms |
576 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
10 ms |
596 KB |
Output is correct |
11 |
Correct |
438 ms |
14624 KB |
Output is correct |
12 |
Correct |
444 ms |
14748 KB |
Output is correct |
13 |
Correct |
368 ms |
14636 KB |
Output is correct |
14 |
Correct |
441 ms |
14672 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 |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
219 ms |
7604 KB |
Output is correct |
24 |
Correct |
156 ms |
5196 KB |
Output is correct |
25 |
Correct |
104 ms |
4056 KB |
Output is correct |
26 |
Correct |
95 ms |
3348 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 |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
8 ms |
468 KB |
Output is correct |
33 |
Correct |
8 ms |
576 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
454 ms |
15460 KB |
Output is correct |
36 |
Correct |
472 ms |
15552 KB |
Output is correct |
37 |
Correct |
471 ms |
15516 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
308 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 |
308 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
9 ms |
560 KB |
Output is correct |
46 |
Correct |
14 ms |
920 KB |
Output is correct |
47 |
Correct |
2 ms |
320 KB |
Output is correct |
48 |
Correct |
72 ms |
3688 KB |
Output is correct |
49 |
Correct |
1 ms |
312 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
8 ms |
504 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
304 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
235 ms |
10064 KB |
Output is correct |
56 |
Correct |
127 ms |
6264 KB |
Output is correct |
57 |
Correct |
159 ms |
6212 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 |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
219 ms |
7604 KB |
Output is correct |
10 |
Correct |
156 ms |
5196 KB |
Output is correct |
11 |
Correct |
104 ms |
4056 KB |
Output is correct |
12 |
Correct |
95 ms |
3348 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 |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
8 ms |
468 KB |
Output is correct |
19 |
Correct |
8 ms |
576 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
454 ms |
15460 KB |
Output is correct |
22 |
Correct |
472 ms |
15552 KB |
Output is correct |
23 |
Correct |
471 ms |
15516 KB |
Output is correct |
24 |
Correct |
73 ms |
3276 KB |
Output is correct |
25 |
Correct |
202 ms |
9260 KB |
Output is correct |
26 |
Correct |
48 ms |
2384 KB |
Output is correct |
27 |
Correct |
491 ms |
20160 KB |
Output is correct |
28 |
Correct |
477 ms |
20044 KB |
Output is correct |
29 |
Correct |
445 ms |
20172 KB |
Output is correct |
30 |
Correct |
465 ms |
20152 KB |
Output is correct |
31 |
Correct |
479 ms |
20256 KB |
Output is correct |
32 |
Correct |
424 ms |
15624 KB |
Output is correct |
33 |
Correct |
461 ms |
20748 KB |
Output is correct |
34 |
Correct |
442 ms |
15540 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
10 ms |
596 KB |
Output is correct |
11 |
Correct |
438 ms |
14624 KB |
Output is correct |
12 |
Correct |
444 ms |
14748 KB |
Output is correct |
13 |
Correct |
368 ms |
14636 KB |
Output is correct |
14 |
Correct |
441 ms |
14672 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 |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
219 ms |
7604 KB |
Output is correct |
24 |
Correct |
156 ms |
5196 KB |
Output is correct |
25 |
Correct |
104 ms |
4056 KB |
Output is correct |
26 |
Correct |
95 ms |
3348 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 |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
8 ms |
468 KB |
Output is correct |
33 |
Correct |
8 ms |
576 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
308 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 |
308 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
9 ms |
560 KB |
Output is correct |
42 |
Correct |
14 ms |
920 KB |
Output is correct |
43 |
Correct |
2 ms |
320 KB |
Output is correct |
44 |
Correct |
72 ms |
3688 KB |
Output is correct |
45 |
Correct |
1 ms |
312 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
8 ms |
504 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
304 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
235 ms |
10064 KB |
Output is correct |
52 |
Correct |
127 ms |
6264 KB |
Output is correct |
53 |
Correct |
159 ms |
6212 KB |
Output is correct |
54 |
Correct |
73 ms |
3276 KB |
Output is correct |
55 |
Correct |
202 ms |
9260 KB |
Output is correct |
56 |
Correct |
48 ms |
2384 KB |
Output is correct |
57 |
Correct |
491 ms |
20160 KB |
Output is correct |
58 |
Correct |
477 ms |
20044 KB |
Output is correct |
59 |
Correct |
445 ms |
20172 KB |
Output is correct |
60 |
Correct |
465 ms |
20152 KB |
Output is correct |
61 |
Correct |
479 ms |
20256 KB |
Output is correct |
62 |
Correct |
424 ms |
15624 KB |
Output is correct |
63 |
Correct |
461 ms |
20748 KB |
Output is correct |
64 |
Correct |
442 ms |
15540 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
454 ms |
15460 KB |
Output is correct |
67 |
Correct |
472 ms |
15552 KB |
Output is correct |
68 |
Correct |
471 ms |
15516 KB |
Output is correct |
69 |
Correct |
54 ms |
2380 KB |
Output is correct |
70 |
Correct |
15 ms |
840 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
64 ms |
3132 KB |
Output is correct |
73 |
Correct |
17 ms |
964 KB |
Output is correct |
74 |
Correct |
2 ms |
340 KB |
Output is correct |
75 |
Correct |
468 ms |
20044 KB |
Output is correct |
76 |
Correct |
466 ms |
20164 KB |
Output is correct |
77 |
Correct |
456 ms |
20160 KB |
Output is correct |
78 |
Correct |
499 ms |
20128 KB |
Output is correct |
79 |
Correct |
508 ms |
20160 KB |
Output is correct |
80 |
Correct |
476 ms |
20168 KB |
Output is correct |
81 |
Correct |
349 ms |
18180 KB |
Output is correct |
82 |
Correct |
352 ms |
18136 KB |
Output is correct |