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
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(n), arr(n);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) {
cin >> b[i];
arr[i] = m * max(a[i], b[i]);
}
int l = 0, r = 1e18 + 1, mid, ans;
while(l <= r) {
mid = (l + r) / 2;
int over = 0, under = 0;
for(int i = 0; i < n; i++) {
if(arr[i] >= mid) over += (arr[i] - mid) / max(a[i], b[i]);
else under += (mid - arr[i]) / b[i] + ((mid - arr[i]) % b[i] ? 1 : 0);
}
if(mid == 18) cout << over << " " << under << "\n";
if(over >= under) {
l = mid + 1;
ans = mid;
} else r = mid - 1;
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# | 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... |