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 <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
typedef long long ll;
typedef long double ld;
const ll SZ = 200'100, LG = 18, INF = 1'000'000'000'000'000'000;
ll n, m;
vector<ll> vec1, vec2;
bool check(ll val) {
vector<ll> vec;
ll left = 0;
for (int i = 0; i < n; i++) {
ll needed = (val - 1) / vec1[i] + 1;
if (needed <= m) {
left += m - needed;
vec.push_back(0);
} else {
vec.push_back(val - m * vec1[i]);
}
}
for (int i = 0; i < n; i++) {
if (vec[i] == 0) continue;
left -= (vec[i] - 1) / vec2[i] + 1;
}
return left >= 0;
}
int main() {
fastInp;
cin >> n >> m;
vec1.resize(n);
vec2.resize(n);
for (auto &c : vec1) cin >> c;
for (auto &c : vec2) cin >> c;
for (int i = 0; i < n; i++) {
vec1[i] = max(vec1[i], vec2[i]);
}
ll l = 0, r = INF;
while (r - l > 1) {
ll mid = (l + r) / 2;
if (check(mid)) {
l = mid;
} else {
r = mid;
}
}
cout << l;
return 0;
}
# | 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... |