#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, x;
cin >> n >> x;
vector<int> t(n);
for (int i = 0; i < n; i++) cin >> t[i];
vector<pair<int, int>> pref(n);
vector<int> lis(0);
for (int i = 0; i < n; i++)
{
if (lis.empty() || (t[i] > lis.back())) pref[i].second = lis.size() + 1;
else
{
int l = lower_bound(lis.begin(), lis.end(), t[i]) - lis.begin();
pref[i].second = l + 1;
}
t[i] -= x;
if (lis.empty() || (t[i] > lis.back()))
{
pref[i].first = lis.size() + 1;
lis.push_back(t[i]);
}
else
{
int l = lower_bound(lis.begin(), lis.end(), t[i]) - lis.begin();
pref[i].first = l + 1;
lis[l] = t[i];
}
}
for (int i = 0; i < n; i++) t[i] = -t[i];
vector<pair<int, int>> sfx(n);
vector<int> lds(0);
for (int i = n - 1; i > -1; i--)
{
if (lds.empty() || (t[i] > lds.back())) sfx[i].second = lds.size() + 1;
else
{
int l = lower_bound(lds.begin(), lds.end(), t[i]) - lds.begin();
sfx[i].second = l + 1;
}
t[i] -= x;
if (lds.empty() || (t[i] > lds.back()))
{
sfx[i].first = lds.size() + 1;
lds.push_back(t[i]);
}
else
{
int l = lower_bound(lds.begin(), lds.end(), t[i]) - lds.begin();
sfx[i].second = l + 1;
lds[l] = t[i];
}
}
int ans = 2;
for (int i = 0; i < n; i++) ans = fmax(ans, pref[i].first + sfx[i].second);
for (int i = 0; i < n; i++) ans = fmax(ans, pref[i].second + sfx[i].first);
cout << --ans;
}
# |
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 |
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 |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
460 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 |
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 |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
456 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 |
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 |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
456 KB |
Output is correct |
19 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
6228 KB |
Output is correct |
2 |
Correct |
44 ms |
6236 KB |
Output is correct |
3 |
Correct |
44 ms |
6136 KB |
Output is correct |
4 |
Correct |
43 ms |
6056 KB |
Output is correct |
5 |
Correct |
19 ms |
6616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1884 KB |
Output is correct |
2 |
Correct |
10 ms |
1884 KB |
Output is correct |
3 |
Correct |
10 ms |
1916 KB |
Output is correct |
4 |
Incorrect |
7 ms |
1980 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
3368 KB |
Output is correct |
2 |
Correct |
17 ms |
3160 KB |
Output is correct |
3 |
Correct |
36 ms |
6224 KB |
Output is correct |
4 |
Correct |
19 ms |
6620 KB |
Output is correct |
5 |
Correct |
11 ms |
3580 KB |
Output is correct |
6 |
Correct |
17 ms |
6448 KB |
Output is correct |
7 |
Correct |
20 ms |
7132 KB |
Output is correct |
8 |
Correct |
14 ms |
3424 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 |
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 |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
456 KB |
Output is correct |
19 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |