#include <iostream>
#include <vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
long long A[300050], B[300050];
int main(){
ios::sync_with_stdio(false); cin.tie(0);
long long N, M;
cin >> N >> M;
loop(i,0,N) cin >> A[i];
loop(i,0,N) cin >> B[i];
loop(i,0,N) A[i] = max(A[i], B[i]);
long long ok = 0, ng = 1LL << 60;
auto check = [&](long long x) -> bool {
long long day = 0;
loop(i,0,N){
if(x <= A[i] * M) day += (x + A[i] - 1) / A[i];
else day += M + (x - A[i] * M + B[i] - 1) / B[i];
// day += min<long long>(((cost-1) / A[i] + 1), M);
// cost -= min<long long>(((cost-1) / A[i] + 1), M) * A[i];
// if(cost > 0)
// day += ((cost-1) / B[i] + 1);
if(day > N * M) return 0;
}
return 1;
};
while(ng - ok > 1){
long long mid = (ng + ok) / 2;
if(check(mid)) ok = mid;
else ng = mid;
}
cout << ok << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
92 ms |
4940 KB |
Output is correct |
12 |
Correct |
93 ms |
4956 KB |
Output is correct |
13 |
Correct |
78 ms |
4924 KB |
Output is correct |
14 |
Correct |
69 ms |
4940 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
31 ms |
4896 KB |
Output is correct |
17 |
Correct |
103 ms |
5084 KB |
Output is correct |
18 |
Correct |
88 ms |
4968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
31 ms |
4896 KB |
Output is correct |
3 |
Correct |
103 ms |
5084 KB |
Output is correct |
4 |
Correct |
88 ms |
4968 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 |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
52 ms |
2608 KB |
Output is correct |
14 |
Correct |
32 ms |
1876 KB |
Output is correct |
15 |
Correct |
24 ms |
1612 KB |
Output is correct |
16 |
Correct |
19 ms |
1156 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
92 ms |
4940 KB |
Output is correct |
12 |
Correct |
93 ms |
4956 KB |
Output is correct |
13 |
Correct |
78 ms |
4924 KB |
Output is correct |
14 |
Correct |
69 ms |
4940 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 |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
52 ms |
2608 KB |
Output is correct |
24 |
Correct |
32 ms |
1876 KB |
Output is correct |
25 |
Correct |
24 ms |
1612 KB |
Output is correct |
26 |
Correct |
19 ms |
1156 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
31 ms |
4896 KB |
Output is correct |
36 |
Correct |
103 ms |
5084 KB |
Output is correct |
37 |
Correct |
88 ms |
4968 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 |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
2 ms |
340 KB |
Output is correct |
46 |
Correct |
3 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
16 ms |
1048 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
2 ms |
340 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 |
55 ms |
2636 KB |
Output is correct |
56 |
Correct |
29 ms |
1900 KB |
Output is correct |
57 |
Correct |
23 ms |
1876 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 |
256 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
52 ms |
2608 KB |
Output is correct |
10 |
Correct |
32 ms |
1876 KB |
Output is correct |
11 |
Correct |
24 ms |
1612 KB |
Output is correct |
12 |
Correct |
19 ms |
1156 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
31 ms |
4896 KB |
Output is correct |
22 |
Correct |
103 ms |
5084 KB |
Output is correct |
23 |
Correct |
88 ms |
4968 KB |
Output is correct |
24 |
Correct |
29 ms |
996 KB |
Output is correct |
25 |
Correct |
70 ms |
2420 KB |
Output is correct |
26 |
Correct |
13 ms |
744 KB |
Output is correct |
27 |
Correct |
96 ms |
5004 KB |
Output is correct |
28 |
Correct |
95 ms |
4992 KB |
Output is correct |
29 |
Correct |
108 ms |
4968 KB |
Output is correct |
30 |
Correct |
120 ms |
5000 KB |
Output is correct |
31 |
Correct |
200 ms |
4992 KB |
Output is correct |
32 |
Correct |
98 ms |
5004 KB |
Output is correct |
33 |
Correct |
199 ms |
5004 KB |
Output is correct |
34 |
Correct |
99 ms |
4940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
92 ms |
4940 KB |
Output is correct |
12 |
Correct |
93 ms |
4956 KB |
Output is correct |
13 |
Correct |
78 ms |
4924 KB |
Output is correct |
14 |
Correct |
69 ms |
4940 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 |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
52 ms |
2608 KB |
Output is correct |
24 |
Correct |
32 ms |
1876 KB |
Output is correct |
25 |
Correct |
24 ms |
1612 KB |
Output is correct |
26 |
Correct |
19 ms |
1156 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
2 ms |
340 KB |
Output is correct |
42 |
Correct |
3 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
16 ms |
1048 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
2 ms |
340 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 |
55 ms |
2636 KB |
Output is correct |
52 |
Correct |
29 ms |
1900 KB |
Output is correct |
53 |
Correct |
23 ms |
1876 KB |
Output is correct |
54 |
Correct |
29 ms |
996 KB |
Output is correct |
55 |
Correct |
70 ms |
2420 KB |
Output is correct |
56 |
Correct |
13 ms |
744 KB |
Output is correct |
57 |
Correct |
96 ms |
5004 KB |
Output is correct |
58 |
Correct |
95 ms |
4992 KB |
Output is correct |
59 |
Correct |
108 ms |
4968 KB |
Output is correct |
60 |
Correct |
120 ms |
5000 KB |
Output is correct |
61 |
Correct |
200 ms |
4992 KB |
Output is correct |
62 |
Correct |
98 ms |
5004 KB |
Output is correct |
63 |
Correct |
199 ms |
5004 KB |
Output is correct |
64 |
Correct |
99 ms |
4940 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
31 ms |
4896 KB |
Output is correct |
67 |
Correct |
103 ms |
5084 KB |
Output is correct |
68 |
Correct |
88 ms |
4968 KB |
Output is correct |
69 |
Correct |
22 ms |
844 KB |
Output is correct |
70 |
Correct |
6 ms |
452 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
31 ms |
1004 KB |
Output is correct |
73 |
Correct |
7 ms |
468 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
95 ms |
4936 KB |
Output is correct |
76 |
Correct |
110 ms |
5044 KB |
Output is correct |
77 |
Correct |
122 ms |
4940 KB |
Output is correct |
78 |
Correct |
154 ms |
5000 KB |
Output is correct |
79 |
Correct |
206 ms |
5004 KB |
Output is correct |
80 |
Correct |
218 ms |
4940 KB |
Output is correct |
81 |
Correct |
185 ms |
4948 KB |
Output is correct |
82 |
Correct |
162 ms |
5092 KB |
Output is correct |