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 pii pair<int, int>
#define ll long long
#define ld long double
using namespace std;
vector<ll> a;
vector<ll> b;
int n; ll m;
bool binary(ll x) {
ll possible = 0;
for (int i = 0; i < n ; i++) {
ll val = a[i] * m;
if (val < x)
continue;
ll diff = val - x;
possible += diff / a[i];
}
for (int i = 0; i < n; i++) {
ll val = a[i] * m;
if (val >= x)
continue;
ll dif = x - val;
possible -= ceil((ld)dif / (ld)b[i]);
}
return possible < 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
a.resize(n);
b.resize(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++)
{
cin >> b[i];
a[i] = max(a[i], b[i]);
}
ll l = 0, r = 6e18;
while (l < r) {
ll mid = (l + r) / 2;
if (binary(mid))
r = mid;
else
l = mid + 1;
}
cout << l - 1<< "\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... |