#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
i64 m;
cin >> n >> m;
vector<i64> a(n);
vector<i64> b(n);
for(int i = 0;i < n;i++){
cin >> a[i];
}
for(int i = 0;i < n;i++){
cin >> b[i];
if(b[i] > a[i]) a[i] = b[i];
}
function<bool(i64)> f = [&](i64 x){
i64 have = 0LL;
for(int i = 0;i < n;i++){
i64 tot = (x + a[i] - 1LL) / a[i];
if(tot <= m){
have += m - tot;
}
}
for(int i = 0;i < n;i++){
i64 tot = (x + a[i] - 1LL) / a[i];
if(tot > m){
i64 tx = x - m * a[i];
assert(tx >= 0LL);
tot = (tx + b[i] - 1LL) / b[i];
assert(tot >= 0);
have -= tot;
// if(have < 0LL) return false;
}
}
// return true;
// return (have >= 0LL);
if(have >= 0LL) return true;
else return false;
};
i64 s = 0;
i64 e = (i64)1e18 + 10LL;
while(e > s){
i64 mid = (e + s + 1LL) / 2LL;
if(f(mid)){
s = mid;
}else{
e = mid - 1LL;
}
}
assert(e == s);
assert(f(e));
cout << e << '\n';
return 0;
}
| # | 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... |