#include <stdio.h>
#define N 300000
#define INF 0x3f3f3f3f3f3f3f3fLL
int max(int a, int b) { return a > b ? a : b; }
int solve(int *aa, int *bb, int n, int m, long long s) {
int i;
long long k_, k;
k_ = (long long) n * m;
for (i = 0; i < n; i++) {
k = s <= (long long) aa[i] * m ? (s + aa[i] - 1) / aa[i] : m + (s - (long long) aa[i] * m + bb[i] - 1) / bb[i];
if (k_ < k)
return 0;
k_ -= k;
}
return 1;
}
int main() {
static int aa[N], bb[N];
int n, m, i;
long long lower, upper;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
for (i = 0; i < n; i++) {
scanf("%d", &bb[i]);
aa[i] = max(aa[i], bb[i]);
}
lower = 0, upper = INF;
while (upper - lower > 1) {
long long s = (lower + upper) / 2;
if (solve(aa, bb, n, m, s))
lower = s;
else
upper = s;
}
printf("%lld\n", lower);
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:27:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:29:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
Main.c:31:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%d", &bb[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
292 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
123 ms |
8312 KB |
Output is correct |
12 |
Correct |
123 ms |
8336 KB |
Output is correct |
13 |
Correct |
125 ms |
6392 KB |
Output is correct |
14 |
Correct |
99 ms |
6380 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
55 ms |
3684 KB |
Output is correct |
17 |
Correct |
123 ms |
9000 KB |
Output is correct |
18 |
Correct |
126 ms |
8384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
55 ms |
3684 KB |
Output is correct |
3 |
Correct |
123 ms |
9000 KB |
Output is correct |
4 |
Correct |
126 ms |
8384 KB |
Output is correct |
5 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
292 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
79 ms |
4348 KB |
Output is correct |
14 |
Correct |
44 ms |
2992 KB |
Output is correct |
15 |
Correct |
32 ms |
2252 KB |
Output is correct |
16 |
Correct |
24 ms |
1876 KB |
Output is correct |
17 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
292 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
123 ms |
8312 KB |
Output is correct |
12 |
Correct |
123 ms |
8336 KB |
Output is correct |
13 |
Correct |
125 ms |
6392 KB |
Output is correct |
14 |
Correct |
99 ms |
6380 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 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 |
1 ms |
292 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
296 KB |
Output is correct |
23 |
Correct |
79 ms |
4348 KB |
Output is correct |
24 |
Correct |
44 ms |
2992 KB |
Output is correct |
25 |
Correct |
32 ms |
2252 KB |
Output is correct |
26 |
Correct |
24 ms |
1876 KB |
Output is correct |
27 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
55 ms |
3684 KB |
Output is correct |
36 |
Correct |
123 ms |
9000 KB |
Output is correct |
37 |
Correct |
126 ms |
8384 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
292 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
296 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
296 KB |
Output is correct |
44 |
Correct |
1 ms |
292 KB |
Output is correct |
45 |
Correct |
3 ms |
340 KB |
Output is correct |
46 |
Correct |
5 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
20 ms |
1668 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
288 KB |
Output is correct |
51 |
Correct |
3 ms |
340 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
60 ms |
4308 KB |
Output is correct |
56 |
Correct |
41 ms |
2324 KB |
Output is correct |
57 |
Correct |
39 ms |
2300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
292 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
79 ms |
4348 KB |
Output is correct |
10 |
Correct |
44 ms |
2992 KB |
Output is correct |
11 |
Correct |
32 ms |
2252 KB |
Output is correct |
12 |
Correct |
24 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
55 ms |
3684 KB |
Output is correct |
22 |
Correct |
123 ms |
9000 KB |
Output is correct |
23 |
Correct |
126 ms |
8384 KB |
Output is correct |
24 |
Correct |
32 ms |
1452 KB |
Output is correct |
25 |
Correct |
82 ms |
3924 KB |
Output is correct |
26 |
Correct |
17 ms |
1144 KB |
Output is correct |
27 |
Correct |
118 ms |
8384 KB |
Output is correct |
28 |
Correct |
118 ms |
8524 KB |
Output is correct |
29 |
Correct |
128 ms |
8368 KB |
Output is correct |
30 |
Correct |
159 ms |
8384 KB |
Output is correct |
31 |
Correct |
228 ms |
8304 KB |
Output is correct |
32 |
Correct |
139 ms |
3892 KB |
Output is correct |
33 |
Correct |
229 ms |
9008 KB |
Output is correct |
34 |
Correct |
128 ms |
3668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
292 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
123 ms |
8312 KB |
Output is correct |
12 |
Correct |
123 ms |
8336 KB |
Output is correct |
13 |
Correct |
125 ms |
6392 KB |
Output is correct |
14 |
Correct |
99 ms |
6380 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 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 |
1 ms |
292 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
296 KB |
Output is correct |
23 |
Correct |
79 ms |
4348 KB |
Output is correct |
24 |
Correct |
44 ms |
2992 KB |
Output is correct |
25 |
Correct |
32 ms |
2252 KB |
Output is correct |
26 |
Correct |
24 ms |
1876 KB |
Output is correct |
27 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
292 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
296 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
296 KB |
Output is correct |
40 |
Correct |
1 ms |
292 KB |
Output is correct |
41 |
Correct |
3 ms |
340 KB |
Output is correct |
42 |
Correct |
5 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
20 ms |
1668 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
288 KB |
Output is correct |
47 |
Correct |
3 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
60 ms |
4308 KB |
Output is correct |
52 |
Correct |
41 ms |
2324 KB |
Output is correct |
53 |
Correct |
39 ms |
2300 KB |
Output is correct |
54 |
Correct |
32 ms |
1452 KB |
Output is correct |
55 |
Correct |
82 ms |
3924 KB |
Output is correct |
56 |
Correct |
17 ms |
1144 KB |
Output is correct |
57 |
Correct |
118 ms |
8384 KB |
Output is correct |
58 |
Correct |
118 ms |
8524 KB |
Output is correct |
59 |
Correct |
128 ms |
8368 KB |
Output is correct |
60 |
Correct |
159 ms |
8384 KB |
Output is correct |
61 |
Correct |
228 ms |
8304 KB |
Output is correct |
62 |
Correct |
139 ms |
3892 KB |
Output is correct |
63 |
Correct |
229 ms |
9008 KB |
Output is correct |
64 |
Correct |
128 ms |
3668 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
55 ms |
3684 KB |
Output is correct |
67 |
Correct |
123 ms |
9000 KB |
Output is correct |
68 |
Correct |
126 ms |
8384 KB |
Output is correct |
69 |
Correct |
24 ms |
1108 KB |
Output is correct |
70 |
Correct |
7 ms |
468 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
35 ms |
1452 KB |
Output is correct |
73 |
Correct |
9 ms |
468 KB |
Output is correct |
74 |
Correct |
2 ms |
304 KB |
Output is correct |
75 |
Correct |
132 ms |
8380 KB |
Output is correct |
76 |
Correct |
132 ms |
8420 KB |
Output is correct |
77 |
Correct |
158 ms |
8484 KB |
Output is correct |
78 |
Correct |
179 ms |
8480 KB |
Output is correct |
79 |
Correct |
229 ms |
8396 KB |
Output is correct |
80 |
Correct |
238 ms |
8420 KB |
Output is correct |
81 |
Correct |
221 ms |
6428 KB |
Output is correct |
82 |
Correct |
170 ms |
6416 KB |
Output is correct |