This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3,unroll-loops,inline,fast-math")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lint = __int128_t;
#define all(a) (a).begin(), (a).end()
#define int ll
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(n);
for (int& i : a)
cin >> i;
for (int& i : b)
cin >> i;
for (int i = 0; i < n; ++i)
a[i] = max(a[i], b[i]);
lint l = 0, r = 1e18 + 228;
while (r - l > 1) {
lint mid = (l + r) / 2;
lint free = 0, need = 0;
for (int i = 0; i < n; ++i) {
if ((lint)m * a[i] < mid) {
lint x = mid - (lint)m * a[i];
need += x / b[i] + bool(x % b[i]);
} else {
free += m - (mid / a[i] + bool(mid % a[i]));
}
}
if (free >= need)
l = mid;
else
r = mid;
}
cout << (int)l;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
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... |