#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main() {
int n, x;
cin >> n >> x;
vector <ll> nums(n);
for (int i = 0; i < n; i++)
cin >> nums[i];
vector <ll> lis(n), dp;
vector <ll> lis_val(n);
for (int i = 0; i < n; i++) {
auto x = lower_bound(dp.begin(), dp.end(), nums[i]);
lis_val[i] = nums[i];
lis[i] = (x - dp.begin()) + 1;
if (x == dp.end())
dp.push_back(nums[i]);
else
*x = nums[i];
}
dp.clear();
for (int i = 0; i < n; i++) {
nums[i] = -(nums[i] + x);
}
ll ans = 0;
for (int i = n-1; i >= 0; i--) {
auto y = lower_bound(dp.begin(), dp.end(), -lis_val[i]);
ans = max(ans, (ll)(y - dp.begin()) + lis[i]);
auto z = lower_bound(dp.begin(), dp.end(), nums[i]);
if (z == dp.end())
dp.push_back(nums[i]);
else
*z = nums[i];
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
4944 KB |
Output is correct |
2 |
Correct |
90 ms |
5052 KB |
Output is correct |
3 |
Correct |
80 ms |
5136 KB |
Output is correct |
4 |
Correct |
82 ms |
5076 KB |
Output is correct |
5 |
Correct |
49 ms |
6200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1624 KB |
Output is correct |
2 |
Correct |
24 ms |
1624 KB |
Output is correct |
3 |
Correct |
20 ms |
1624 KB |
Output is correct |
4 |
Correct |
13 ms |
1880 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
12 ms |
1880 KB |
Output is correct |
7 |
Correct |
19 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
2640 KB |
Output is correct |
2 |
Correct |
46 ms |
2640 KB |
Output is correct |
3 |
Correct |
75 ms |
5064 KB |
Output is correct |
4 |
Correct |
61 ms |
6088 KB |
Output is correct |
5 |
Correct |
25 ms |
3276 KB |
Output is correct |
6 |
Correct |
45 ms |
5888 KB |
Output is correct |
7 |
Correct |
68 ms |
5868 KB |
Output is correct |
8 |
Correct |
36 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
80 ms |
4944 KB |
Output is correct |
28 |
Correct |
90 ms |
5052 KB |
Output is correct |
29 |
Correct |
80 ms |
5136 KB |
Output is correct |
30 |
Correct |
82 ms |
5076 KB |
Output is correct |
31 |
Correct |
49 ms |
6200 KB |
Output is correct |
32 |
Correct |
20 ms |
1624 KB |
Output is correct |
33 |
Correct |
24 ms |
1624 KB |
Output is correct |
34 |
Correct |
20 ms |
1624 KB |
Output is correct |
35 |
Correct |
13 ms |
1880 KB |
Output is correct |
36 |
Correct |
0 ms |
344 KB |
Output is correct |
37 |
Correct |
12 ms |
1880 KB |
Output is correct |
38 |
Correct |
19 ms |
1628 KB |
Output is correct |
39 |
Correct |
36 ms |
2640 KB |
Output is correct |
40 |
Correct |
46 ms |
2640 KB |
Output is correct |
41 |
Correct |
75 ms |
5064 KB |
Output is correct |
42 |
Correct |
61 ms |
6088 KB |
Output is correct |
43 |
Correct |
25 ms |
3276 KB |
Output is correct |
44 |
Correct |
45 ms |
5888 KB |
Output is correct |
45 |
Correct |
68 ms |
5868 KB |
Output is correct |
46 |
Correct |
36 ms |
2648 KB |
Output is correct |
47 |
Correct |
40 ms |
3664 KB |
Output is correct |
48 |
Correct |
43 ms |
3664 KB |
Output is correct |
49 |
Correct |
83 ms |
6992 KB |
Output is correct |
50 |
Correct |
49 ms |
7364 KB |
Output is correct |
51 |
Correct |
42 ms |
5832 KB |
Output is correct |
52 |
Correct |
51 ms |
7368 KB |
Output is correct |
53 |
Correct |
64 ms |
7464 KB |
Output is correct |
54 |
Correct |
62 ms |
8136 KB |
Output is correct |
55 |
Correct |
73 ms |
6992 KB |
Output is correct |