#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=3e14;
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 |
1 ms |
212 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 |
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 |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
345 ms |
8300 KB |
Output is correct |
12 |
Correct |
368 ms |
8296 KB |
Output is correct |
13 |
Correct |
210 ms |
4880 KB |
Output is correct |
14 |
Correct |
384 ms |
11600 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
82 ms |
4888 KB |
Output is correct |
17 |
Correct |
294 ms |
4972 KB |
Output is correct |
18 |
Correct |
256 ms |
5216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
82 ms |
4888 KB |
Output is correct |
3 |
Correct |
294 ms |
4972 KB |
Output is correct |
4 |
Correct |
256 ms |
5216 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 |
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 |
129 ms |
2584 KB |
Output is correct |
14 |
Correct |
85 ms |
1772 KB |
Output is correct |
15 |
Correct |
69 ms |
1372 KB |
Output is correct |
16 |
Correct |
55 ms |
1232 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
312 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 |
340 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 |
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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
345 ms |
8300 KB |
Output is correct |
12 |
Correct |
368 ms |
8296 KB |
Output is correct |
13 |
Correct |
210 ms |
4880 KB |
Output is correct |
14 |
Correct |
384 ms |
11600 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 |
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 |
129 ms |
2584 KB |
Output is correct |
24 |
Correct |
85 ms |
1772 KB |
Output is correct |
25 |
Correct |
69 ms |
1372 KB |
Output is correct |
26 |
Correct |
55 ms |
1232 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
312 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 |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
82 ms |
4888 KB |
Output is correct |
36 |
Correct |
294 ms |
4972 KB |
Output is correct |
37 |
Correct |
256 ms |
5216 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 |
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 |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
5 ms |
360 KB |
Output is correct |
46 |
Correct |
10 ms |
520 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
59 ms |
1572 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
5 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 |
174 ms |
4332 KB |
Output is correct |
56 |
Correct |
79 ms |
1784 KB |
Output is correct |
57 |
Correct |
104 ms |
3744 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 |
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 |
129 ms |
2584 KB |
Output is correct |
10 |
Correct |
85 ms |
1772 KB |
Output is correct |
11 |
Correct |
69 ms |
1372 KB |
Output is correct |
12 |
Correct |
55 ms |
1232 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
312 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 |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
82 ms |
4888 KB |
Output is correct |
22 |
Correct |
294 ms |
4972 KB |
Output is correct |
23 |
Correct |
256 ms |
5216 KB |
Output is correct |
24 |
Incorrect |
51 ms |
1000 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
345 ms |
8300 KB |
Output is correct |
12 |
Correct |
368 ms |
8296 KB |
Output is correct |
13 |
Correct |
210 ms |
4880 KB |
Output is correct |
14 |
Correct |
384 ms |
11600 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 |
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 |
129 ms |
2584 KB |
Output is correct |
24 |
Correct |
85 ms |
1772 KB |
Output is correct |
25 |
Correct |
69 ms |
1372 KB |
Output is correct |
26 |
Correct |
55 ms |
1232 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
312 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 |
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 |
0 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 |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
5 ms |
360 KB |
Output is correct |
42 |
Correct |
10 ms |
520 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
59 ms |
1572 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
5 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 |
174 ms |
4332 KB |
Output is correct |
52 |
Correct |
79 ms |
1784 KB |
Output is correct |
53 |
Correct |
104 ms |
3744 KB |
Output is correct |
54 |
Incorrect |
51 ms |
1000 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |