#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
const int inf=1e18+5000;
signed main()
{
int n,m;cin>>n>>m;
int a[n+1],b[n+1];
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)cin>>b[i];
int l=1,r=inf,mid=l+(r-l)/2,res=0;
while(l<=r)
{
//printf("%lld %lld %lld: ",l,mid,r);
int sum=0;
for(int i=1;i<=n;i++)
{
int x,z,k=inf;
if(a[i]<=b[i])
{
x=0;
z=(mid+b[i]-1)/b[i];
k=max(x,z);
}
else
{
x=mid/a[i];
if(x>m) x=m;
z=(mid-x*(a[i]-b[i])+b[i]-1)/b[i];
k=min(k,max(x,z));
x++;
if(x>m) x=m;
z=(mid-x*(a[i]-b[i])+b[i]-1)/b[i];
k=min(k,max(x,z));
}
sum+=k;
/*int k1=inf;
for(int j=0;j<=m;j++)
{
int z=ceil((double)(mid-j*(a[i]-b[i]))/b[i]);
k1=min(k1,max(j,z));
}*/
/*int x=0;
if(a[i]>b[i])x=min(mid/(a[i]-b[i]),m);
sum+=ceil((mid-x*(a[i]-b[i]))/b[i]);*/
//cout<<"|"<<k<<" "<<k1<<"| ";
}
//cout<<endl;
if(sum<=n*m)
{
res=mid;
l=mid+1;
}
else r=mid-1;
mid=l+(r-l)/2;
}
cout<<res<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
130 ms |
2652 KB |
Output is correct |
10 |
Correct |
85 ms |
1968 KB |
Output is correct |
11 |
Correct |
64 ms |
1584 KB |
Output is correct |
12 |
Correct |
51 ms |
1344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
214 ms |
5108 KB |
Output is correct |
22 |
Correct |
272 ms |
5096 KB |
Output is correct |
23 |
Correct |
257 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
130 ms |
2652 KB |
Output is correct |
10 |
Correct |
85 ms |
1968 KB |
Output is correct |
11 |
Correct |
64 ms |
1584 KB |
Output is correct |
12 |
Correct |
51 ms |
1344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
214 ms |
5108 KB |
Output is correct |
22 |
Correct |
272 ms |
5096 KB |
Output is correct |
23 |
Correct |
257 ms |
4952 KB |
Output is correct |
24 |
Correct |
47 ms |
1112 KB |
Output is correct |
25 |
Correct |
126 ms |
2396 KB |
Output is correct |
26 |
Correct |
28 ms |
856 KB |
Output is correct |
27 |
Correct |
255 ms |
4956 KB |
Output is correct |
28 |
Correct |
255 ms |
5112 KB |
Output is correct |
29 |
Correct |
258 ms |
5096 KB |
Output is correct |
30 |
Correct |
265 ms |
5104 KB |
Output is correct |
31 |
Correct |
305 ms |
4956 KB |
Output is correct |
32 |
Correct |
233 ms |
4956 KB |
Output is correct |
33 |
Correct |
329 ms |
5100 KB |
Output is correct |
34 |
Correct |
235 ms |
5100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |