#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("input.000","r",stdin);
// freopen("output.000","w",stdout);
// srand((unsigned)time(NULL));
// rand()
int n,a[300005],b[300005],i,ans,l,r,w,m,sum;
cin>>n>>m;
for (i=1;i<n+1;i++) cin>>a[i];
for (i=1;i<n+1;i++) cin>>b[i];
ans=0;l=0;r=1e18;
while (l<=r)
{
w=(l+r)/2;
sum=0;
for (i=1;i<n+1;i++)
if (a[i]>b[i])
{
if (a[i]*m>=w) sum += w/a[i] + (w%a[i]!=0);
else sum += m + (w-a[i]*m)/b[i] + ((w-a[i]*m)%b[i]!=0);
}
else sum += w/b[i] + (w%b[i]!=0);
// cout<<w<<" "<<sum<<"\n";
if (sum<=n*m)
{
ans=w;l=w+1;
}
else r=w-1;
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5012 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5004 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
5008 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
5 ms |
5024 KB |
Output is correct |
11 |
Correct |
168 ms |
10828 KB |
Output is correct |
12 |
Correct |
161 ms |
10784 KB |
Output is correct |
13 |
Correct |
154 ms |
8820 KB |
Output is correct |
14 |
Incorrect |
298 ms |
8832 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5008 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5008 KB |
Output is correct |
4 |
Correct |
3 ms |
5012 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
83 ms |
7808 KB |
Output is correct |
10 |
Correct |
54 ms |
6912 KB |
Output is correct |
11 |
Correct |
41 ms |
6404 KB |
Output is correct |
12 |
Correct |
34 ms |
6092 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5020 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Incorrect |
7 ms |
4948 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5012 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5004 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
5008 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
5 ms |
5024 KB |
Output is correct |
11 |
Correct |
168 ms |
10828 KB |
Output is correct |
12 |
Correct |
161 ms |
10784 KB |
Output is correct |
13 |
Correct |
154 ms |
8820 KB |
Output is correct |
14 |
Incorrect |
298 ms |
8832 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5008 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5008 KB |
Output is correct |
4 |
Correct |
3 ms |
5012 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
83 ms |
7808 KB |
Output is correct |
10 |
Correct |
54 ms |
6912 KB |
Output is correct |
11 |
Correct |
41 ms |
6404 KB |
Output is correct |
12 |
Correct |
34 ms |
6092 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5020 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Incorrect |
7 ms |
4948 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5012 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5004 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
5008 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
5 ms |
5024 KB |
Output is correct |
11 |
Correct |
168 ms |
10828 KB |
Output is correct |
12 |
Correct |
161 ms |
10784 KB |
Output is correct |
13 |
Correct |
154 ms |
8820 KB |
Output is correct |
14 |
Incorrect |
298 ms |
8832 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |