#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define INF (ll)(9e18)
#define int LL
using namespace std;
using LL=long long;
using pii=pair<int,int>;
const int MAXN=300030;
int a[MAXN];
int b[MAXN];
bool check(int n,int m,int tar){
int s=0,d=0;
For(i,1,n){
int t=tar;
int r=min(m,(t+a[i]-1)/a[i]);
t-=r*a[i];
if(t>0){
d+=(t+b[i]-1)/b[i];
}else{
s+=m-r;
}
}
return s>=d;
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(0);
// OAO
int n,m; cin>>n>>m;
For(i,1,n) cin>>a[i];
For(i,1,n){
cin>>b[i];
a[i]=max(a[i],b[i]);
}
int hi=1e18+10;
int lo=0;
while(hi-lo>1){
int mi=(hi+lo)/2;
if(check(n,m,mi)) lo=mi;
else hi=mi;
}
cout<<lo<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
247 ms |
4936 KB |
Output is correct |
12 |
Correct |
232 ms |
5060 KB |
Output is correct |
13 |
Correct |
242 ms |
4992 KB |
Output is correct |
14 |
Incorrect |
485 ms |
4932 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
122 ms |
3188 KB |
Output is correct |
10 |
Correct |
80 ms |
2452 KB |
Output is correct |
11 |
Correct |
60 ms |
1984 KB |
Output is correct |
12 |
Correct |
50 ms |
1824 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Incorrect |
10 ms |
400 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
247 ms |
4936 KB |
Output is correct |
12 |
Correct |
232 ms |
5060 KB |
Output is correct |
13 |
Correct |
242 ms |
4992 KB |
Output is correct |
14 |
Incorrect |
485 ms |
4932 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
122 ms |
3188 KB |
Output is correct |
10 |
Correct |
80 ms |
2452 KB |
Output is correct |
11 |
Correct |
60 ms |
1984 KB |
Output is correct |
12 |
Correct |
50 ms |
1824 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Incorrect |
10 ms |
400 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
247 ms |
4936 KB |
Output is correct |
12 |
Correct |
232 ms |
5060 KB |
Output is correct |
13 |
Correct |
242 ms |
4992 KB |
Output is correct |
14 |
Incorrect |
485 ms |
4932 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |