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>
#define x first
#define y second
#define sz(a) (int)a.size()
#define pb push_back
#define int long long
using namespace std;
typedef long long ll;
void solve();
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
int a[300010], b[300010];
int n, m;
int check(int x) {
int cnt = m * n;
for (int i = 0; i < n; ++i) {
if (a[i] > b[i]) {
int f = (x + a[i] - 1) / a[i];
if (f <= m)
cnt -= f;
else {
cnt -= m;
cnt -= (x - a[i] * m + b[i] - 1) / b[i];
}
} else {
cnt -= (x + b[i] - 1) / b[i];
}
if (cnt < 0)
return false;
}
return true;
}
void solve() {
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i)
cin >> b[i];
int l = 0, r = 2e18;
while (r - l > 1) {
int mid = (r + l) / 2;
if (check(mid))
l = mid;
else
r = mid;
}
cout << l << endl;
}
//923953850098595069
//890909762780980010
# | 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... |