#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MN = 300001;
const ll INF = 1e18 + 71;
ll n, m, A[MN], B[MN];
ll mini = INF;
bool ok(ll val, int dbg) {
if(!val) return 1;
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);
if(dbg) {
assert((m - ((val - 1) / A[i] + 1) == 0));
}
assert((m - ((val - 1) / A[i] + 1)) >= 0);
} else {
nr_sar -= (val - m * A[i] - 1) / B[i] + 1;
assert(((val - m * A[i] - 1) / B[i] + 1) >= 0);
}
if(nr_sar < - n * m) return 0;
if(dbg) assert(!(nr_sar > 0));
}
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];
}
for(int i = 1; i <= n; ++i) mini = min(A[i], mini);
ll st = 0, dr = INF, mij;
while(st < dr) {
mij = st + (dr - st + 1) / 2;
if(ok(mij, 0)) {
st = mij;
} else dr = mij - 1;
}
if(m == 1) {
ok(st, 1);
assert(st == mini);
cout << st << "\n";
} else
cout << st << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
234 ms |
6576 KB |
Output is correct |
12 |
Correct |
215 ms |
6532 KB |
Output is correct |
13 |
Correct |
194 ms |
6648 KB |
Output is correct |
14 |
Correct |
153 ms |
6612 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
69 ms |
6096 KB |
Output is correct |
17 |
Correct |
246 ms |
11316 KB |
Output is correct |
18 |
Correct |
203 ms |
10732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
69 ms |
6096 KB |
Output is correct |
3 |
Correct |
246 ms |
11316 KB |
Output is correct |
4 |
Correct |
203 ms |
10732 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
112 ms |
4288 KB |
Output is correct |
14 |
Correct |
70 ms |
3280 KB |
Output is correct |
15 |
Correct |
61 ms |
2340 KB |
Output is correct |
16 |
Correct |
50 ms |
2048 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
234 ms |
6576 KB |
Output is correct |
12 |
Correct |
215 ms |
6532 KB |
Output is correct |
13 |
Correct |
194 ms |
6648 KB |
Output is correct |
14 |
Correct |
153 ms |
6612 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
112 ms |
4288 KB |
Output is correct |
24 |
Correct |
70 ms |
3280 KB |
Output is correct |
25 |
Correct |
61 ms |
2340 KB |
Output is correct |
26 |
Correct |
50 ms |
2048 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
5 ms |
444 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
69 ms |
6096 KB |
Output is correct |
36 |
Correct |
246 ms |
11316 KB |
Output is correct |
37 |
Correct |
203 ms |
10732 KB |
Output is correct |
38 |
Correct |
0 ms |
312 KB |
Output is correct |
39 |
Correct |
1 ms |
308 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
304 KB |
Output is correct |
45 |
Correct |
4 ms |
452 KB |
Output is correct |
46 |
Correct |
7 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
46 ms |
2092 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
4 ms |
468 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
117 ms |
5448 KB |
Output is correct |
56 |
Correct |
64 ms |
3020 KB |
Output is correct |
57 |
Correct |
49 ms |
3032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
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 |
112 ms |
4288 KB |
Output is correct |
10 |
Correct |
70 ms |
3280 KB |
Output is correct |
11 |
Correct |
61 ms |
2340 KB |
Output is correct |
12 |
Correct |
50 ms |
2048 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
5 ms |
444 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
69 ms |
6096 KB |
Output is correct |
22 |
Correct |
246 ms |
11316 KB |
Output is correct |
23 |
Correct |
203 ms |
10732 KB |
Output is correct |
24 |
Correct |
47 ms |
1856 KB |
Output is correct |
25 |
Correct |
123 ms |
4916 KB |
Output is correct |
26 |
Correct |
25 ms |
1364 KB |
Output is correct |
27 |
Correct |
273 ms |
10700 KB |
Output is correct |
28 |
Correct |
213 ms |
10780 KB |
Output is correct |
29 |
Correct |
217 ms |
10736 KB |
Output is correct |
30 |
Correct |
267 ms |
10780 KB |
Output is correct |
31 |
Correct |
314 ms |
10788 KB |
Output is correct |
32 |
Correct |
183 ms |
6152 KB |
Output is correct |
33 |
Correct |
349 ms |
11436 KB |
Output is correct |
34 |
Correct |
200 ms |
6144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
234 ms |
6576 KB |
Output is correct |
12 |
Correct |
215 ms |
6532 KB |
Output is correct |
13 |
Correct |
194 ms |
6648 KB |
Output is correct |
14 |
Correct |
153 ms |
6612 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
112 ms |
4288 KB |
Output is correct |
24 |
Correct |
70 ms |
3280 KB |
Output is correct |
25 |
Correct |
61 ms |
2340 KB |
Output is correct |
26 |
Correct |
50 ms |
2048 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
5 ms |
444 KB |
Output is correct |
34 |
Correct |
0 ms |
312 KB |
Output is correct |
35 |
Correct |
1 ms |
308 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
304 KB |
Output is correct |
41 |
Correct |
4 ms |
452 KB |
Output is correct |
42 |
Correct |
7 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
46 ms |
2092 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
4 ms |
468 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
117 ms |
5448 KB |
Output is correct |
52 |
Correct |
64 ms |
3020 KB |
Output is correct |
53 |
Correct |
49 ms |
3032 KB |
Output is correct |
54 |
Correct |
47 ms |
1856 KB |
Output is correct |
55 |
Correct |
123 ms |
4916 KB |
Output is correct |
56 |
Correct |
25 ms |
1364 KB |
Output is correct |
57 |
Correct |
273 ms |
10700 KB |
Output is correct |
58 |
Correct |
213 ms |
10780 KB |
Output is correct |
59 |
Correct |
217 ms |
10736 KB |
Output is correct |
60 |
Correct |
267 ms |
10780 KB |
Output is correct |
61 |
Correct |
314 ms |
10788 KB |
Output is correct |
62 |
Correct |
183 ms |
6152 KB |
Output is correct |
63 |
Correct |
349 ms |
11436 KB |
Output is correct |
64 |
Correct |
200 ms |
6144 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
69 ms |
6096 KB |
Output is correct |
67 |
Correct |
246 ms |
11316 KB |
Output is correct |
68 |
Correct |
203 ms |
10732 KB |
Output is correct |
69 |
Correct |
34 ms |
1364 KB |
Output is correct |
70 |
Correct |
9 ms |
588 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
53 ms |
1760 KB |
Output is correct |
73 |
Correct |
10 ms |
596 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
229 ms |
10768 KB |
Output is correct |
76 |
Correct |
231 ms |
10788 KB |
Output is correct |
77 |
Correct |
243 ms |
10748 KB |
Output is correct |
78 |
Correct |
279 ms |
10784 KB |
Output is correct |
79 |
Correct |
337 ms |
10788 KB |
Output is correct |
80 |
Correct |
347 ms |
10760 KB |
Output is correct |
81 |
Correct |
287 ms |
8800 KB |
Output is correct |
82 |
Correct |
294 ms |
8920 KB |
Output is correct |