#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++) {
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
129 ms |
6580 KB |
Output is correct |
10 |
Correct |
87 ms |
6572 KB |
Output is correct |
11 |
Correct |
65 ms |
6588 KB |
Output is correct |
12 |
Correct |
54 ms |
6748 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
4 ms |
4444 KB |
Output is correct |
19 |
Correct |
5 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
212 ms |
7252 KB |
Output is correct |
22 |
Correct |
270 ms |
7452 KB |
Output is correct |
23 |
Correct |
256 ms |
7440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
129 ms |
6580 KB |
Output is correct |
10 |
Correct |
87 ms |
6572 KB |
Output is correct |
11 |
Correct |
65 ms |
6588 KB |
Output is correct |
12 |
Correct |
54 ms |
6748 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
4 ms |
4444 KB |
Output is correct |
19 |
Correct |
5 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
212 ms |
7252 KB |
Output is correct |
22 |
Correct |
270 ms |
7452 KB |
Output is correct |
23 |
Correct |
256 ms |
7440 KB |
Output is correct |
24 |
Correct |
48 ms |
6736 KB |
Output is correct |
25 |
Correct |
131 ms |
6568 KB |
Output is correct |
26 |
Correct |
30 ms |
6748 KB |
Output is correct |
27 |
Correct |
258 ms |
7272 KB |
Output is correct |
28 |
Correct |
261 ms |
7248 KB |
Output is correct |
29 |
Correct |
261 ms |
7332 KB |
Output is correct |
30 |
Correct |
286 ms |
7456 KB |
Output is correct |
31 |
Correct |
320 ms |
7252 KB |
Output is correct |
32 |
Correct |
213 ms |
7252 KB |
Output is correct |
33 |
Correct |
173 ms |
7328 KB |
Output is correct |
34 |
Correct |
216 ms |
8568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |