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 = m;
ll t = target - a*dat[i].first;
if (t<=-dat[i].first){
a -= (-t)/dat[i].first;
t = target - a*dat[i].first;
}else if (t>0){
a += t/dat[i].second;
t -= t/dat[i].second*dat[i].second;
if (t>0){
a++;
}
}
time += a;
}
return time<=n*m;
}
ll check(ll l, ll r){
if (l >= r) return l;
ll mid = (r+l+1)/2;
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(1,5e18) << "\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... |