이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
const int mxn = 3e5 + 10;
const int mxm = 1e9 + 10;
const int inf = 3e18 + 10;
int a[mxn], b[mxn], x[mxn];
int n, m;
void build() {
for(int i = 0; i < n; i++) {
a[i] = max(a[i], b[i]);
x[i] = a[i] * m;
}
}
int sus(int s, int a) {
return (s + a - 1) / a;
}
bool can(int MID) {
int MIN = 0, MAX = 0;
for(int i = 0; i < n; i++) {
if(x[i] < MID) MIN += (MID - x[i] + b[i] - 1) / b[i];
if(x[i] > MID) MAX += min(m, (x[i] - MID) / a[i]);
MIN = min(MIN, inf);
MAX = min(MAX, inf);
}
return MIN <= MAX;
}
signed main() {
cin >> n >> m;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int j = 0; j < n; j++)
cin >> b[j];
build();
int L = 1e18 + 10, R = 1e18 + 10;
for(int i = 0; i < n; i++)
L = min(L, x[i]);
while(R - L > 1) {
int M = (L + R) / 2;
if(can(M)) L = M;
else R = M;
}
cout << L << '\n';
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... |