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;
typedef long long ll;
ll n,m;
vector<pair<ll,ll> > dat;
bool isok(ll target){ // ans>=target;
ll time = 0;
for (int i = 0;i<n;i++){
ll a = min(((target-1)/dat[i].first)+1,m);
ll t = target - a*dat[i].first;
time += a;
if (t>0){
time += ((t-1)/dat[i].second)+1;
}
}
return time<=n*m;
}
ll check(ll l, ll r){
if (l >= r) return l;
ll mid = (r-l+1)/2+l;
if (isok(mid)){
return check(mid,r);
}else{
return check(l,mid-1);
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin >> n >> m;
dat.resize(n);
for (int i = 0;i<n;i++){
cin >> dat[i].first;
}
for (int i = 0;i<n;i++){
cin >> dat[i].second;
dat[i].first = max(dat[i].first, dat[i].second);
}
cout << check(1LL,1000000000000000000LL) << "\n";
}
# | 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... |