//Dedicated to my love, ivaziva
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
const int N=3e5+5;
ll n, m;
ll a[N], b[N];
bool check(ll mid) {
vector<ll> c;
c.pb(0);
for (int i=1; i<=n; i++) {
c.pb((max(a[i], b[i])*m));
}
ll tot=0;
for (int i=1; i<=n; i++) {
if (tot>=(ll)(1e18))
break;
int v=c[i];
if (mid==v)
continue;
else if (mid>v) {
ll kol=((mid-v)/b[i]);
if ((v%b[i])!=0)
++kol;
tot+=kol;
}
else {
tot-=((v-mid)/max(a[i], b[i]));
}
}
return (tot<=0);
}
int main () {
ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> m;
for (ll i=1; i<=n; i++)
cin >> a[i];
for (ll i=1; i<=n; i++)
cin >> b[i];
ll lo=1, hi=(ll)(1e18), ans=0;
while (lo<=hi) {
ll mid=(lo+hi)/2;
if (check(mid)) {
lo=mid+1;
ans=mid;
}
else {
hi=mid-1;
}
}
cout << ans << '\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... |