#include <cstdio>
inline int max(int a, int b) {
return a > b ? a : b;
}
int n, X, res;
const int maxN = 2e5+10;
int dp_max[maxN];
int dp_min[maxN];
int mx_i, mn_i;
int find(int* dp, int i, int val) {
int a = -1, b = i, avg;
while(b - a > 1) {
avg = (a + b) / 2;
if(dp[avg] < val) a = avg;
else b = avg;
}
return b;
}
int add(int* dp, int &i, int val) {
int b = find(dp, i, val);
dp[b] = val;
i = max(i, b + 1);
return b;
}
void count(int left) {
if(left == 0)
return;
int val;
scanf("%d", &val);
int b_here = add(dp_max, mx_i, val);
count(left - 1);
res = max(b_here + find(dp_min, mn_i, -val+X) + 1, res);
add(dp_min, mn_i, -val);
}
int main() {
scanf("%d%d", &n, &X);
count(n);
printf("%d\n", res);
}
Compilation message
glo.cpp: In function 'void count(int)':
glo.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &val);
~~~~~^~~~~~~~~~~~
glo.cpp: In function 'int main()':
glo.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &X);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
10488 KB |
Output is correct |
2 |
Correct |
75 ms |
11644 KB |
Output is correct |
3 |
Correct |
91 ms |
11640 KB |
Output is correct |
4 |
Correct |
77 ms |
11640 KB |
Output is correct |
5 |
Correct |
89 ms |
11680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
3072 KB |
Output is correct |
2 |
Correct |
21 ms |
3200 KB |
Output is correct |
3 |
Correct |
19 ms |
3072 KB |
Output is correct |
4 |
Correct |
20 ms |
3200 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
22 ms |
3200 KB |
Output is correct |
7 |
Correct |
19 ms |
3200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
5752 KB |
Output is correct |
2 |
Correct |
38 ms |
6008 KB |
Output is correct |
3 |
Correct |
76 ms |
11640 KB |
Output is correct |
4 |
Correct |
99 ms |
11740 KB |
Output is correct |
5 |
Correct |
40 ms |
6008 KB |
Output is correct |
6 |
Correct |
65 ms |
11128 KB |
Output is correct |
7 |
Correct |
76 ms |
11768 KB |
Output is correct |
8 |
Correct |
35 ms |
6052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
73 ms |
10488 KB |
Output is correct |
28 |
Correct |
75 ms |
11644 KB |
Output is correct |
29 |
Correct |
91 ms |
11640 KB |
Output is correct |
30 |
Correct |
77 ms |
11640 KB |
Output is correct |
31 |
Correct |
89 ms |
11680 KB |
Output is correct |
32 |
Correct |
20 ms |
3072 KB |
Output is correct |
33 |
Correct |
21 ms |
3200 KB |
Output is correct |
34 |
Correct |
19 ms |
3072 KB |
Output is correct |
35 |
Correct |
20 ms |
3200 KB |
Output is correct |
36 |
Correct |
0 ms |
288 KB |
Output is correct |
37 |
Correct |
22 ms |
3200 KB |
Output is correct |
38 |
Correct |
19 ms |
3200 KB |
Output is correct |
39 |
Correct |
37 ms |
5752 KB |
Output is correct |
40 |
Correct |
38 ms |
6008 KB |
Output is correct |
41 |
Correct |
76 ms |
11640 KB |
Output is correct |
42 |
Correct |
99 ms |
11740 KB |
Output is correct |
43 |
Correct |
40 ms |
6008 KB |
Output is correct |
44 |
Correct |
65 ms |
11128 KB |
Output is correct |
45 |
Correct |
76 ms |
11768 KB |
Output is correct |
46 |
Correct |
35 ms |
6052 KB |
Output is correct |
47 |
Correct |
40 ms |
6016 KB |
Output is correct |
48 |
Correct |
37 ms |
6008 KB |
Output is correct |
49 |
Correct |
76 ms |
11640 KB |
Output is correct |
50 |
Correct |
91 ms |
11640 KB |
Output is correct |
51 |
Correct |
67 ms |
8952 KB |
Output is correct |
52 |
Correct |
83 ms |
11768 KB |
Output is correct |
53 |
Correct |
69 ms |
11768 KB |
Output is correct |
54 |
Correct |
81 ms |
12408 KB |
Output is correct |
55 |
Correct |
71 ms |
11640 KB |
Output is correct |