#include <iostream>
#include <vector>
using namespace std;
long long n , x,v[200005],pref[200005];
int main()
{
cin >> n >> x;
vector<long long> dp (n+1,1e9);
for ( int i = 1; i <= n ; i ++)
cin >> v[i];
long long maxx = 0 ;
for ( int i = 1; i <= n ; i ++ )
{
long long poz = lower_bound(dp.begin(),dp.end(),v[i]) - dp.begin();
maxx = max ( maxx , poz );
dp[poz]= v[i];
pref[i] = poz + 1;
}
dp = vector<long long> (n+1,1e9);
for ( int i = n ; i >= 1; i -- )
{
long long poz = lower_bound(dp.begin(),dp.end(),-v[i]) - dp.begin();
long long cox = lower_bound(dp.begin(),dp.end(),-v[i]+x) - dp.begin();
maxx = max ( maxx, pref[i] + cox);
dp[poz] = -v[i];
}
cout << maxx << '\n';
return 0;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:11:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
11 | for ( int i = 1; i <= n ; i ++)
| ^~~
glo.cpp:14:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
14 | long long maxx = 0 ;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
0 ms |
444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
0 ms |
444 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 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 |
1 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 |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
8592 KB |
Output is correct |
2 |
Correct |
82 ms |
8488 KB |
Output is correct |
3 |
Correct |
70 ms |
8532 KB |
Output is correct |
4 |
Correct |
73 ms |
8436 KB |
Output is correct |
5 |
Correct |
52 ms |
7760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2396 KB |
Output is correct |
2 |
Correct |
17 ms |
2396 KB |
Output is correct |
3 |
Correct |
17 ms |
2452 KB |
Output is correct |
4 |
Correct |
12 ms |
2140 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
12 ms |
2140 KB |
Output is correct |
7 |
Correct |
16 ms |
2360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
4328 KB |
Output is correct |
2 |
Correct |
33 ms |
4436 KB |
Output is correct |
3 |
Correct |
90 ms |
8476 KB |
Output is correct |
4 |
Correct |
50 ms |
7780 KB |
Output is correct |
5 |
Correct |
29 ms |
3920 KB |
Output is correct |
6 |
Correct |
47 ms |
7508 KB |
Output is correct |
7 |
Correct |
62 ms |
8136 KB |
Output is correct |
8 |
Correct |
33 ms |
4432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
0 ms |
444 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 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 |
1 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 |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
82 ms |
8592 KB |
Output is correct |
28 |
Correct |
82 ms |
8488 KB |
Output is correct |
29 |
Correct |
70 ms |
8532 KB |
Output is correct |
30 |
Correct |
73 ms |
8436 KB |
Output is correct |
31 |
Correct |
52 ms |
7760 KB |
Output is correct |
32 |
Correct |
17 ms |
2396 KB |
Output is correct |
33 |
Correct |
17 ms |
2396 KB |
Output is correct |
34 |
Correct |
17 ms |
2452 KB |
Output is correct |
35 |
Correct |
12 ms |
2140 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
12 ms |
2140 KB |
Output is correct |
38 |
Correct |
16 ms |
2360 KB |
Output is correct |
39 |
Correct |
37 ms |
4328 KB |
Output is correct |
40 |
Correct |
33 ms |
4436 KB |
Output is correct |
41 |
Correct |
90 ms |
8476 KB |
Output is correct |
42 |
Correct |
50 ms |
7780 KB |
Output is correct |
43 |
Correct |
29 ms |
3920 KB |
Output is correct |
44 |
Correct |
47 ms |
7508 KB |
Output is correct |
45 |
Correct |
62 ms |
8136 KB |
Output is correct |
46 |
Correct |
33 ms |
4432 KB |
Output is correct |
47 |
Correct |
35 ms |
4516 KB |
Output is correct |
48 |
Correct |
38 ms |
4436 KB |
Output is correct |
49 |
Correct |
82 ms |
8384 KB |
Output is correct |
50 |
Correct |
51 ms |
7764 KB |
Output is correct |
51 |
Correct |
42 ms |
5956 KB |
Output is correct |
52 |
Correct |
52 ms |
7760 KB |
Output is correct |
53 |
Correct |
51 ms |
7760 KB |
Output is correct |
54 |
Correct |
64 ms |
8440 KB |
Output is correct |
55 |
Correct |
71 ms |
8532 KB |
Output is correct |