// 還要更強
#include<iostream>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<math.h>
#include<cstring>
#include<stack>
#include<string.h>
#include<random>
#include<algorithm>
#include<vector>
#include <cassert>
#define ll long long
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define INF (ll)(2e18)
#define pb push_back
#define F first
#define S second
using namespace std;
ll n,m;
ll A[300005],B[300005];
bool check(ll x){
ll res=0;
FOR(i,0,n){
ll tmp=x;
if(1ll*A[i]*m<tmp){
tmp-=A[i]*m;
if(B[i]<=0) exit(-1);
res-=tmp/B[i]+(tmp%B[i]?1:0);
}
else{
ll used=1;
res+=0;
}
}
if(res>=0) return 1;
return 0;
}
signed main(){
cin>>n>>m;
FOR(i,0,n){
cin>>A[i];
}
FOR(i,0,n){
cin>>B[i]; A[i]=max(A[i],B[i]);
}
ll l=1,r=(1e18+1),ans=1;
while(l<r){
ll mid=(l+r)>>1;
if(check(mid)){
ans=max(ans,mid); l=mid+1;
}
else{
r=mid;
}
}
cout<<ans<<endl;
}
Compilation message
Main.cpp: In function 'bool check(long long int)':
Main.cpp:39:16: warning: unused variable 'used' [-Wunused-variable]
39 | ll used=1;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
5 ms |
332 KB |
Output is correct |
11 |
Correct |
308 ms |
4956 KB |
Output is correct |
12 |
Correct |
316 ms |
4920 KB |
Output is correct |
13 |
Correct |
244 ms |
4852 KB |
Output is correct |
14 |
Correct |
323 ms |
4964 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
246 ms |
4892 KB |
Output is correct |
17 |
Correct |
342 ms |
4968 KB |
Output is correct |
18 |
Correct |
299 ms |
4916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
246 ms |
4892 KB |
Output is correct |
3 |
Correct |
342 ms |
4968 KB |
Output is correct |
4 |
Correct |
299 ms |
4916 KB |
Output is correct |
5 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
5 ms |
332 KB |
Output is correct |
11 |
Correct |
308 ms |
4956 KB |
Output is correct |
12 |
Correct |
316 ms |
4920 KB |
Output is correct |
13 |
Correct |
244 ms |
4852 KB |
Output is correct |
14 |
Correct |
323 ms |
4964 KB |
Output is correct |
15 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
5 ms |
332 KB |
Output is correct |
11 |
Correct |
308 ms |
4956 KB |
Output is correct |
12 |
Correct |
316 ms |
4920 KB |
Output is correct |
13 |
Correct |
244 ms |
4852 KB |
Output is correct |
14 |
Correct |
323 ms |
4964 KB |
Output is correct |
15 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |