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 int long long
#define pii pair<int, int>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int>a(n), b(n);
for (auto &i : a) cin >> i;
for (auto &i : b) cin >> i;
int l = -1, r = (long long)1e18 + 5, mid;
while (l + 1 < r) {
mid = (l + r) / 2;
int need = 0;
for (int i = 0 ; i < n ; i++) {
if (a[i] > b[i]) {
if (mid > (__int128)a[i] * m) need += m + (mid - a[i] * m) / b[i] + ((mid - a[i] * m) % b[i] != 0ll ? 1ll : 0ll);
else need += (mid / a[i]) + (mid % a[i] != 0ll ? 1ll : 0ll);
} else {
need += (mid / b[i]) + (mid % b[i] != 0ll ? 1ll : 0ll);
}
if(need > n * m) break;
}
if (need <= n * m) {
l = mid;
//cout << l << " " << need << "\n";
} else {
r = mid;
}
}
cout << l << "\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... |