#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
ll n,m;
ll a[300001],b[300001];
bool check(ll f){
ll raod=n*m;
vector<ll> v;
ll cnt=0;
for(ll k=1;k<=n;k++){
if(b[k]>=a[k]){
cnt=f/b[k];
if(f%b[k]!=0)
cnt++;
if(cnt>raod)
return 0;
raod-=cnt;
}
else{
v.push_back(k);
}
}
ll dar=0;
for(ll ind:v){
ll i=a[ind];
ll j=b[ind];
cnt=f/i;
if(f%i!=0)
cnt++;
if(cnt>m)
cnt=m;
if(raod<cnt)
return 0;
raod-=cnt;
dar=f-cnt*i;
if(dar<=0)
continue;
cnt=dar/j;
if(dar%j!=0)
cnt++;
if(raod<cnt)
return 0;
raod-=cnt;
}
if(raod<0)
return 0;
else
return 1;
}
int main(){
cin>>n>>m;
for(ll k=1;k<=n;k++){
cin>>a[k];
}
for(ll k=1;k<=n;k++){
cin>>b[k];
}
ll l=0,r=2*1e18;
ll md;
bool bl;
while(l<r){
md=(l+r+1)/2;
bl=check(md);
if(bl==1){
l=md;
}
else{
r=md-1;
}
}
cout<<l;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
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 |
4 ms |
344 KB |
Output is correct |
11 |
Correct |
327 ms |
8308 KB |
Output is correct |
12 |
Correct |
351 ms |
8304 KB |
Output is correct |
13 |
Correct |
199 ms |
4924 KB |
Output is correct |
14 |
Correct |
359 ms |
11600 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
78 ms |
4876 KB |
Output is correct |
17 |
Correct |
260 ms |
4872 KB |
Output is correct |
18 |
Correct |
255 ms |
4968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
78 ms |
4876 KB |
Output is correct |
3 |
Correct |
260 ms |
4872 KB |
Output is correct |
4 |
Correct |
255 ms |
4968 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
126 ms |
2544 KB |
Output is correct |
14 |
Correct |
90 ms |
1852 KB |
Output is correct |
15 |
Correct |
62 ms |
1380 KB |
Output is correct |
16 |
Correct |
55 ms |
1152 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 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 |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
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 |
4 ms |
344 KB |
Output is correct |
11 |
Correct |
327 ms |
8308 KB |
Output is correct |
12 |
Correct |
351 ms |
8304 KB |
Output is correct |
13 |
Correct |
199 ms |
4924 KB |
Output is correct |
14 |
Correct |
359 ms |
11600 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 |
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 |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
126 ms |
2544 KB |
Output is correct |
24 |
Correct |
90 ms |
1852 KB |
Output is correct |
25 |
Correct |
62 ms |
1380 KB |
Output is correct |
26 |
Correct |
55 ms |
1152 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 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 |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
5 ms |
372 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
78 ms |
4876 KB |
Output is correct |
36 |
Correct |
260 ms |
4872 KB |
Output is correct |
37 |
Correct |
255 ms |
4968 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 |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 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 |
368 KB |
Output is correct |
46 |
Correct |
11 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
268 KB |
Output is correct |
48 |
Correct |
56 ms |
1576 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
6 ms |
340 KB |
Output is correct |
52 |
Correct |
0 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 |
167 ms |
4320 KB |
Output is correct |
56 |
Correct |
66 ms |
1752 KB |
Output is correct |
57 |
Correct |
116 ms |
3848 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
126 ms |
2544 KB |
Output is correct |
10 |
Correct |
90 ms |
1852 KB |
Output is correct |
11 |
Correct |
62 ms |
1380 KB |
Output is correct |
12 |
Correct |
55 ms |
1152 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 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 |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
5 ms |
372 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
78 ms |
4876 KB |
Output is correct |
22 |
Correct |
260 ms |
4872 KB |
Output is correct |
23 |
Correct |
255 ms |
4968 KB |
Output is correct |
24 |
Correct |
52 ms |
928 KB |
Output is correct |
25 |
Correct |
139 ms |
2440 KB |
Output is correct |
26 |
Correct |
32 ms |
680 KB |
Output is correct |
27 |
Correct |
247 ms |
4944 KB |
Output is correct |
28 |
Correct |
266 ms |
4956 KB |
Output is correct |
29 |
Correct |
257 ms |
4972 KB |
Output is correct |
30 |
Correct |
296 ms |
4872 KB |
Output is correct |
31 |
Correct |
367 ms |
4876 KB |
Output is correct |
32 |
Correct |
167 ms |
5068 KB |
Output is correct |
33 |
Correct |
402 ms |
4940 KB |
Output is correct |
34 |
Correct |
168 ms |
4976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
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 |
4 ms |
344 KB |
Output is correct |
11 |
Correct |
327 ms |
8308 KB |
Output is correct |
12 |
Correct |
351 ms |
8304 KB |
Output is correct |
13 |
Correct |
199 ms |
4924 KB |
Output is correct |
14 |
Correct |
359 ms |
11600 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 |
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 |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
126 ms |
2544 KB |
Output is correct |
24 |
Correct |
90 ms |
1852 KB |
Output is correct |
25 |
Correct |
62 ms |
1380 KB |
Output is correct |
26 |
Correct |
55 ms |
1152 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 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 |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
5 ms |
372 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 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 |
368 KB |
Output is correct |
42 |
Correct |
11 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
268 KB |
Output is correct |
44 |
Correct |
56 ms |
1576 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
6 ms |
340 KB |
Output is correct |
48 |
Correct |
0 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 |
167 ms |
4320 KB |
Output is correct |
52 |
Correct |
66 ms |
1752 KB |
Output is correct |
53 |
Correct |
116 ms |
3848 KB |
Output is correct |
54 |
Correct |
52 ms |
928 KB |
Output is correct |
55 |
Correct |
139 ms |
2440 KB |
Output is correct |
56 |
Correct |
32 ms |
680 KB |
Output is correct |
57 |
Correct |
247 ms |
4944 KB |
Output is correct |
58 |
Correct |
266 ms |
4956 KB |
Output is correct |
59 |
Correct |
257 ms |
4972 KB |
Output is correct |
60 |
Correct |
296 ms |
4872 KB |
Output is correct |
61 |
Correct |
367 ms |
4876 KB |
Output is correct |
62 |
Correct |
167 ms |
5068 KB |
Output is correct |
63 |
Correct |
402 ms |
4940 KB |
Output is correct |
64 |
Correct |
168 ms |
4976 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
78 ms |
4876 KB |
Output is correct |
67 |
Correct |
260 ms |
4872 KB |
Output is correct |
68 |
Correct |
255 ms |
4968 KB |
Output is correct |
69 |
Correct |
49 ms |
1072 KB |
Output is correct |
70 |
Correct |
13 ms |
496 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
74 ms |
1420 KB |
Output is correct |
73 |
Correct |
12 ms |
576 KB |
Output is correct |
74 |
Correct |
2 ms |
212 KB |
Output is correct |
75 |
Correct |
368 ms |
8288 KB |
Output is correct |
76 |
Correct |
369 ms |
8300 KB |
Output is correct |
77 |
Correct |
383 ms |
8228 KB |
Output is correct |
78 |
Correct |
438 ms |
8456 KB |
Output is correct |
79 |
Correct |
550 ms |
8296 KB |
Output is correct |
80 |
Correct |
501 ms |
8232 KB |
Output is correct |
81 |
Correct |
328 ms |
4976 KB |
Output is correct |
82 |
Correct |
493 ms |
11552 KB |
Output is correct |