// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL N, X;
LL A[200005];
LL PR[200005];
LL dp[200005];
int main() {
cin >> N >> X;
for (int i = 1; i <= N; i++) {
cin >> A[i];
}
LL res = 0;
dp[1] = A[1];
LL E = 2;
for (int i = 2; i <= N; i++) {
int ind = lower_bound(dp+1,dp+E,A[i])-dp;
PR[i]=ind;
res = max(res,PR[i]);
dp[ind] = A[i];
if (ind==E) {
E++;
}
}
dp[1]=-A[N];
E=2;
for (int i = N-1; i>=1; i--) {
int ind = lower_bound(dp+1,dp+E,X-A[i])-dp;
res = max(res,PR[i]+ind-1);
ind = lower_bound(dp+1,dp+E,-A[i])-dp;
dp[ind]=-A[i];
if (ind == E) {
E++;
}
}
cout << res << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
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 |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
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 |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 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 |
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 |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
5372 KB |
Output is correct |
2 |
Correct |
73 ms |
5436 KB |
Output is correct |
3 |
Correct |
82 ms |
5456 KB |
Output is correct |
4 |
Correct |
71 ms |
5460 KB |
Output is correct |
5 |
Correct |
45 ms |
5460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1628 KB |
Output is correct |
2 |
Correct |
17 ms |
1628 KB |
Output is correct |
3 |
Correct |
17 ms |
1628 KB |
Output is correct |
4 |
Correct |
10 ms |
1624 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1624 KB |
Output is correct |
7 |
Correct |
16 ms |
1608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
2900 KB |
Output is correct |
2 |
Correct |
32 ms |
2952 KB |
Output is correct |
3 |
Correct |
78 ms |
5440 KB |
Output is correct |
4 |
Correct |
42 ms |
5356 KB |
Output is correct |
5 |
Correct |
20 ms |
2908 KB |
Output is correct |
6 |
Correct |
38 ms |
5284 KB |
Output is correct |
7 |
Correct |
53 ms |
5972 KB |
Output is correct |
8 |
Correct |
30 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
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 |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 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 |
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 |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
68 ms |
5372 KB |
Output is correct |
28 |
Correct |
73 ms |
5436 KB |
Output is correct |
29 |
Correct |
82 ms |
5456 KB |
Output is correct |
30 |
Correct |
71 ms |
5460 KB |
Output is correct |
31 |
Correct |
45 ms |
5460 KB |
Output is correct |
32 |
Correct |
17 ms |
1628 KB |
Output is correct |
33 |
Correct |
17 ms |
1628 KB |
Output is correct |
34 |
Correct |
17 ms |
1628 KB |
Output is correct |
35 |
Correct |
10 ms |
1624 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
10 ms |
1624 KB |
Output is correct |
38 |
Correct |
16 ms |
1608 KB |
Output is correct |
39 |
Correct |
32 ms |
2900 KB |
Output is correct |
40 |
Correct |
32 ms |
2952 KB |
Output is correct |
41 |
Correct |
78 ms |
5440 KB |
Output is correct |
42 |
Correct |
42 ms |
5356 KB |
Output is correct |
43 |
Correct |
20 ms |
2908 KB |
Output is correct |
44 |
Correct |
38 ms |
5284 KB |
Output is correct |
45 |
Correct |
53 ms |
5972 KB |
Output is correct |
46 |
Correct |
30 ms |
2908 KB |
Output is correct |
47 |
Correct |
35 ms |
2764 KB |
Output is correct |
48 |
Correct |
35 ms |
3024 KB |
Output is correct |
49 |
Correct |
68 ms |
5320 KB |
Output is correct |
50 |
Correct |
42 ms |
5460 KB |
Output is correct |
51 |
Correct |
33 ms |
4216 KB |
Output is correct |
52 |
Correct |
42 ms |
5460 KB |
Output is correct |
53 |
Correct |
42 ms |
5464 KB |
Output is correct |
54 |
Correct |
74 ms |
6284 KB |
Output is correct |
55 |
Correct |
62 ms |
5316 KB |
Output is correct |