This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define all(X) X.begin(),X.end()
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
setio();
int n,m;
cin>>n>>m;
vector<pii>v;
for(int i=0;i<n;i++){
int a;
cin>>a;
v.pb({a,0});
}
for(int i=0;i<n;i++){
int a;
cin>>a;
v[i].S=a;
}
sort(all(v),greater<>());
int l=0,r=(int)1e18;
while(l<r){
int mm=l+r+1>>1;
int left=0;
bool ok=1;
for(int i=0;i<n;i++){
if(v[i].F>=v[i].S){
if(v[i].F*m>mm){
int x=ceil((double)mm/v[i].F);
left+=m-x;
}
else{
int cur=mm;
cur-=m*v[i].F;
int x=ceil((double)cur/v[i].S);
left-=x;
if(left<0){
ok=0;
break;
}
}
}
else{
left+=m;
int x=ceil((double)mm/v[i].S);
left-=x;
if(left<0){
ok=0;
break;
}
}
}
if(ok){
l=mm;
}
else{
r=mm-1;
}
}
cout<<l<<'\n';
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:38:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | int mm=l+r+1>>1;
| ~~~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |