#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 20;
const ll MAXN = 3e5 + 100;
vector<ll> A, B;
ll N, M;
bool check(ll x) {
ll need = 0;
for (int i = 1; i <= N; i++) {
if (M * A[i] >= x)
need += (x + A[i] - 1) / A[i];
else
need += M + (x - A[i] * M + B[i] - 1) / B[i];
}
return (need <= N * M);
}
int main() {
fast
cin >> N >> M;
A = vector<ll>(N+1);
B = vector<ll>(N+1);
for (int i = 1; i <= N; i++)
cin >> A[i];
for (int i = 1; i <= N; i++)
cin >> B[i];
for (int i = 1; i <= N; i++)
A[i] = max(A[i], B[i]);
ll L = 0;
ll R = 2 * 1e18;
ll ans = -1;
while (L <= R) {
ll mid = L + (R-L)/2;
if (check(mid)) {
L = mid + 1;
ans = mid;
} else
R = mid - 1;
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
452 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
148 ms |
11032 KB |
Output is correct |
12 |
Correct |
147 ms |
10836 KB |
Output is correct |
13 |
Correct |
135 ms |
8860 KB |
Output is correct |
14 |
Incorrect |
273 ms |
8952 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
73 ms |
5692 KB |
Output is correct |
10 |
Correct |
49 ms |
3932 KB |
Output is correct |
11 |
Correct |
39 ms |
3044 KB |
Output is correct |
12 |
Correct |
30 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Incorrect |
4 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
452 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
148 ms |
11032 KB |
Output is correct |
12 |
Correct |
147 ms |
10836 KB |
Output is correct |
13 |
Correct |
135 ms |
8860 KB |
Output is correct |
14 |
Incorrect |
273 ms |
8952 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
73 ms |
5692 KB |
Output is correct |
10 |
Correct |
49 ms |
3932 KB |
Output is correct |
11 |
Correct |
39 ms |
3044 KB |
Output is correct |
12 |
Correct |
30 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Incorrect |
4 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
452 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
148 ms |
11032 KB |
Output is correct |
12 |
Correct |
147 ms |
10836 KB |
Output is correct |
13 |
Correct |
135 ms |
8860 KB |
Output is correct |
14 |
Incorrect |
273 ms |
8952 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |