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<ll> a,b;
bool isok(ll target){ // ans>=target;
ll time = 0;
for (ll i = 0;i<n;i++){
ll x = m;
ll t = target - x*a[i];
if (t<=-a[i]){
x -= (-t)/a[i];
t = target - x*a[i];
}else if (t>0){
x += t/b[i];
t -= (t/b[i])*b[i];
while (t>0){
x++;
t-=b[i];
}
}
time += x;
if (time>n*m) return false;
}
return true;
}
ll check(ll l, ll r){
if (l >= r) return l;
ll mid = (l+r)/2;
if (isok(mid+1)){
return check(mid+1,r);
}else{
return check(l,mid);
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin >> n >> m;
a.resize(n,0);
b.resize(n,0);
for (ll i = 0;i<n;i++){
cin >> a[i];
}
for (ll i = 0;i<n;i++){
cin >> b[i];
a[i] = max(a[i], b[i]);
}
cout << check(0,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... |