이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
ll needed = dif / b[i];
if (dif % b[i])
needed++;
possible -= needed;
}
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 = 5e18;
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... |