// IamHereForFun //
#include <bits/stdc++.h>
using namespace std;
#define LSOne(S) ((S) & -(S))
const int N = 1e5 + 5;
const int M = 513;
const int K = 4;
const int LG = 20;
const long long INF = -1e18;
const int MOD = 1e9 + 7;
const int B = 50;
int n, d, a[N], val[N], ans = 0;
vector<int> v;
void solve()
{
cin >> n >> d;
for (int x = 0; x < n; x++)
{
cin >> a[x];
}
for (int x = n - 1; x >= 0; x--)
{
int i = -a[x];
auto it = lower_bound(v.begin(), v.end(), i);
if (it == v.end())
{
v.push_back(i);
}
else
{
v[it - v.begin()] = i;
}
if (x > 0)
{
auto it = lower_bound(v.begin(), v.end(), -(a[x - 1] - x));
val[x] = (it - v.begin());
}
else
{
val[x] = v.size();
}
// cout << val[x] << " " << x + 1 << "\n";
}
ans = val[0];
v.clear();
for (int x = 0; x < n - 1; x++)
{
int i = a[x] - x;
auto it = lower_bound(v.begin(), v.end(), i);
if(it == v.end())
{
v.push_back(i);
}
else
{
v[it - v.begin()] = i;
}
ans = max(ans, (int)v.size() + val[x + 1]);
}
cout << ans << "\n";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
for (int x = 1; x <= t; x++)
{
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |