#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MN = 300001;
const ll INF = 1e18;
ll n, m, A[MN], B[MN];
bool ok(ll val) {
ll nr_sar = 0;
for(int i = 1; i <= n; ++i) {
if((val - 1) / A[i] + 1 <= m) {
nr_sar += m - ((val - 1) / A[i] + 1);
} else {
nr_sar -= (val - m * A[i] - 1) / B[i] + 1;
}
}
return (nr_sar >= 0);
}
int main() {
cin >> n >> m;
for(int i = 1; i <= n; ++i) cin >> A[i];
for(int i = 1; i <= n; ++i) {
cin >> B[i];
if(A[i] < B[i]) A[i] = B[i];
}
ll st = 0, dr = INF, mij;
while(st < dr) {
mij = st + (dr - st + 1) / 2;
if(ok(mij)) {
st = mij;
} else dr = mij - 1;
}
cout << st << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
448 KB |
Output is correct |
11 |
Correct |
322 ms |
10720 KB |
Output is correct |
12 |
Correct |
326 ms |
10848 KB |
Output is correct |
13 |
Correct |
318 ms |
8800 KB |
Output is correct |
14 |
Incorrect |
511 ms |
8792 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
162 ms |
5544 KB |
Output is correct |
10 |
Correct |
114 ms |
3796 KB |
Output is correct |
11 |
Correct |
80 ms |
2916 KB |
Output is correct |
12 |
Correct |
66 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
308 KB |
Output is correct |
15 |
Correct |
0 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Incorrect |
9 ms |
324 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
448 KB |
Output is correct |
11 |
Correct |
322 ms |
10720 KB |
Output is correct |
12 |
Correct |
326 ms |
10848 KB |
Output is correct |
13 |
Correct |
318 ms |
8800 KB |
Output is correct |
14 |
Incorrect |
511 ms |
8792 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
162 ms |
5544 KB |
Output is correct |
10 |
Correct |
114 ms |
3796 KB |
Output is correct |
11 |
Correct |
80 ms |
2916 KB |
Output is correct |
12 |
Correct |
66 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
308 KB |
Output is correct |
15 |
Correct |
0 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Incorrect |
9 ms |
324 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
448 KB |
Output is correct |
11 |
Correct |
322 ms |
10720 KB |
Output is correct |
12 |
Correct |
326 ms |
10848 KB |
Output is correct |
13 |
Correct |
318 ms |
8800 KB |
Output is correct |
14 |
Incorrect |
511 ms |
8792 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |