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 endl "\n"
vector<pair<int,int>> v;
int n,m;
bool check(int mid){
vector<int> need(n,0);
int left = 0;
for(int i = 0; i<n; i++){
int z = max(v[i].first, v[i].second);
int k = (mid+z-1)/z;
need[i] = max(0ll,mid-(v[i].second * z));
left+=max(0ll,m-k);
}
for(int i = 0; i<n; i++){
if(need[i] <= 0) continue;
left -= max(0ll,(need[i] + v[i].second - 1)/v[i].second);
}
return left>=0;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
v.resize(n);
for(auto& x : v) cin>>x.first; //a
for(auto& x : v) cin>>x.second; //b
int l = 0; int r = LLONG_MAX;
while(r > l+1){
int mid = (l+r)/2;
if(check(mid)) l = mid;
else r = mid;
}
cout<<l<<endl;
}
# | 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... |