#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
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 = 0, r = lis.size() - 1;
while (l < r)
{
int m = l + (r - l) / 2;
if (lis[m] < t[i]) l = m + 1;
else r = m;
}
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 = 0, r = lis.size() - 1;
while (l < r)
{
int m = l + (r - l) / 2;
if (lis[m] < t[i]) l = m + 1;
else r = m;
}
pref[i].first = l + 1;
lis[l] = 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 = 0, r = lds.size() - 1;
while (l < r)
{
int m = l + (r - l) / 2;
if (lds[m] > t[i]) l = m + 1;
else r = m;
}
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 = 0, r = lds.size() - 1;
while (l < r)
{
int m = l + (r - l) / 2;
if (lds[m] > t[i]) l = m + 1;
else r = m;
}
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);
ans--;
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
452 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 |
348 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 |
452 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 |
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 |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
452 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 |
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 |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 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 |
38 ms |
6236 KB |
Output is correct |
2 |
Correct |
38 ms |
6164 KB |
Output is correct |
3 |
Correct |
39 ms |
6280 KB |
Output is correct |
4 |
Correct |
38 ms |
6124 KB |
Output is correct |
5 |
Correct |
19 ms |
6612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1884 KB |
Output is correct |
2 |
Correct |
11 ms |
1884 KB |
Output is correct |
3 |
Correct |
9 ms |
1940 KB |
Output is correct |
4 |
Incorrect |
4 ms |
1884 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
3356 KB |
Output is correct |
2 |
Correct |
15 ms |
3164 KB |
Output is correct |
3 |
Correct |
32 ms |
6232 KB |
Output is correct |
4 |
Correct |
16 ms |
6620 KB |
Output is correct |
5 |
Correct |
10 ms |
3408 KB |
Output is correct |
6 |
Correct |
14 ms |
6316 KB |
Output is correct |
7 |
Correct |
16 ms |
7132 KB |
Output is correct |
8 |
Correct |
13 ms |
3416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
452 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 |
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 |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |