#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn = 3e5 + 10;
const int mxm = 1e9 + 10;
ll a[mxn], b[mxn], x[mxn];
int n, m, id[mxn];
void build() {
for(int i = 0; i < n; i++) {
a[i] = max(a[i], b[i]);
x[i] = a[i] * m;
id[i] = i;
}
sort(id, id + n, [&](int i, int j) {
return x[i] < x[j];
});
}
ll sus(ll s, ll a) {
if(s % a == 0) return s / a;
return s / a + 1;
}
bool can(ll MID) {
ll MIN = 0, MAX = 0;
for(int t = 0; t < n; t++) {
int i = id[t];
if(x[i] < MID) MIN += sus((MID - x[i]), b[i]);
if(x[i] > MID) MAX += sus((x[i] - MID), a[i]);
}
return MIN <= MAX;
}
int 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();
ll L = 0, R = 1e18 + 10;
while(R - L > 1) {
ll M = L + (R - L) / 2;
if(can(M)) L = M;
else R = M;
}
cout << L << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |