#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int n, k; cin >> n >> k; vector<int> a(n), b(n);
int l = 0, r = 0;
for(int i=0;i<n;i++) {cin >> a[i]; r = max(r,a[i]);}
for(int i=0;i<n;i++) {cin >> b[i]; r = max(r,b[i]);}
r *= k;
while(l<r) {
int m = l+(r-l+1)/2, c = 0;
for(int i=0;i<n;i++) {
if(m <= k*max(a[i],b[i])) c += (k-(m+max(a[i],b[i])-1)/max(a[i],b[i]));
else c -= (m-k*max(a[i],b[i])+b[i]-1)/b[i];
if(c <= -n*k) {r = m-1; break;}
}
if(c >= 0) l = m;
else r = m-1;
}
cout << l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
160 ms |
5112 KB |
Output is correct |
12 |
Correct |
168 ms |
5116 KB |
Output is correct |
13 |
Correct |
130 ms |
5120 KB |
Output is correct |
14 |
Correct |
130 ms |
5116 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
51 ms |
6228 KB |
Output is correct |
17 |
Correct |
184 ms |
11344 KB |
Output is correct |
18 |
Correct |
164 ms |
10832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
51 ms |
6228 KB |
Output is correct |
3 |
Correct |
184 ms |
11344 KB |
Output is correct |
4 |
Correct |
164 ms |
10832 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
83 ms |
2652 KB |
Output is correct |
14 |
Correct |
57 ms |
1880 KB |
Output is correct |
15 |
Correct |
41 ms |
1368 KB |
Output is correct |
16 |
Correct |
44 ms |
1372 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
160 ms |
5112 KB |
Output is correct |
12 |
Correct |
168 ms |
5116 KB |
Output is correct |
13 |
Correct |
130 ms |
5120 KB |
Output is correct |
14 |
Correct |
130 ms |
5116 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
83 ms |
2652 KB |
Output is correct |
24 |
Correct |
57 ms |
1880 KB |
Output is correct |
25 |
Correct |
41 ms |
1368 KB |
Output is correct |
26 |
Correct |
44 ms |
1372 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
520 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
51 ms |
6228 KB |
Output is correct |
36 |
Correct |
184 ms |
11344 KB |
Output is correct |
37 |
Correct |
164 ms |
10832 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
604 KB |
Output is correct |
43 |
Correct |
0 ms |
604 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
4 ms |
604 KB |
Output is correct |
46 |
Correct |
5 ms |
744 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
30 ms |
2132 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
4 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
83 ms |
5440 KB |
Output is correct |
56 |
Correct |
42 ms |
3276 KB |
Output is correct |
57 |
Correct |
43 ms |
3152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
9 |
Correct |
83 ms |
2652 KB |
Output is correct |
10 |
Correct |
57 ms |
1880 KB |
Output is correct |
11 |
Correct |
41 ms |
1368 KB |
Output is correct |
12 |
Correct |
44 ms |
1372 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 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 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
520 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
51 ms |
6228 KB |
Output is correct |
22 |
Correct |
184 ms |
11344 KB |
Output is correct |
23 |
Correct |
164 ms |
10832 KB |
Output is correct |
24 |
Correct |
28 ms |
1884 KB |
Output is correct |
25 |
Correct |
86 ms |
5076 KB |
Output is correct |
26 |
Correct |
18 ms |
1372 KB |
Output is correct |
27 |
Correct |
170 ms |
10744 KB |
Output is correct |
28 |
Correct |
166 ms |
10760 KB |
Output is correct |
29 |
Correct |
177 ms |
10752 KB |
Output is correct |
30 |
Correct |
212 ms |
10836 KB |
Output is correct |
31 |
Correct |
212 ms |
10832 KB |
Output is correct |
32 |
Correct |
75 ms |
6224 KB |
Output is correct |
33 |
Correct |
201 ms |
11376 KB |
Output is correct |
34 |
Correct |
71 ms |
6236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
160 ms |
5112 KB |
Output is correct |
12 |
Correct |
168 ms |
5116 KB |
Output is correct |
13 |
Correct |
130 ms |
5120 KB |
Output is correct |
14 |
Correct |
130 ms |
5116 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
83 ms |
2652 KB |
Output is correct |
24 |
Correct |
57 ms |
1880 KB |
Output is correct |
25 |
Correct |
41 ms |
1368 KB |
Output is correct |
26 |
Correct |
44 ms |
1372 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
520 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
604 KB |
Output is correct |
39 |
Correct |
0 ms |
604 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
4 ms |
604 KB |
Output is correct |
42 |
Correct |
5 ms |
744 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
30 ms |
2132 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
4 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
83 ms |
5440 KB |
Output is correct |
52 |
Correct |
42 ms |
3276 KB |
Output is correct |
53 |
Correct |
43 ms |
3152 KB |
Output is correct |
54 |
Correct |
28 ms |
1884 KB |
Output is correct |
55 |
Correct |
86 ms |
5076 KB |
Output is correct |
56 |
Correct |
18 ms |
1372 KB |
Output is correct |
57 |
Correct |
170 ms |
10744 KB |
Output is correct |
58 |
Correct |
166 ms |
10760 KB |
Output is correct |
59 |
Correct |
177 ms |
10752 KB |
Output is correct |
60 |
Correct |
212 ms |
10836 KB |
Output is correct |
61 |
Correct |
212 ms |
10832 KB |
Output is correct |
62 |
Correct |
75 ms |
6224 KB |
Output is correct |
63 |
Correct |
201 ms |
11376 KB |
Output is correct |
64 |
Correct |
71 ms |
6236 KB |
Output is correct |
65 |
Correct |
0 ms |
344 KB |
Output is correct |
66 |
Correct |
51 ms |
6228 KB |
Output is correct |
67 |
Correct |
184 ms |
11344 KB |
Output is correct |
68 |
Correct |
164 ms |
10832 KB |
Output is correct |
69 |
Correct |
21 ms |
1372 KB |
Output is correct |
70 |
Correct |
6 ms |
712 KB |
Output is correct |
71 |
Correct |
1 ms |
344 KB |
Output is correct |
72 |
Correct |
28 ms |
1868 KB |
Output is correct |
73 |
Correct |
7 ms |
604 KB |
Output is correct |
74 |
Correct |
1 ms |
348 KB |
Output is correct |
75 |
Correct |
166 ms |
10880 KB |
Output is correct |
76 |
Correct |
178 ms |
10832 KB |
Output is correct |
77 |
Correct |
196 ms |
10876 KB |
Output is correct |
78 |
Correct |
179 ms |
10836 KB |
Output is correct |
79 |
Correct |
193 ms |
10832 KB |
Output is correct |
80 |
Correct |
184 ms |
10832 KB |
Output is correct |
81 |
Correct |
147 ms |
8788 KB |
Output is correct |
82 |
Correct |
181 ms |
8828 KB |
Output is correct |