This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
const int MAXN = 3e5 + 10;
int n, a[MAXN], d, dp[MAXN];
int fp[410][410];
void solve()
{
cin >> n >> d;
for (int i = 1; i <= n; i ++)
{
cin >> a[i];
}
/**for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++)
fp[i][j] = -1e9;
for (int i = 1; i <= n; i ++)
{
fp[i][i] = max(fp[i][i], 1);
for (int j = i - 1; j >= max(1, i - d); j --)
{
for (int k = 1; k <= n; k ++)
{
if (a[i] > a[k])
{
fp[i][i] = max(fp[j][k] + 1, fp[i][i]);
}
else
{
fp[i][k] = max(fp[i][k], fp[j][k]);
}
}
}
}*/
int s = 0;
for (int j = 1; j <= n; j ++)
s = max(s, fp[n][j]);
//cout << s << endl;
//return;
int res = 0;
for (int i = 1; i <= n; i ++)
{
dp[i] = max(dp[i], 1);
int ls = i;
for (int j = i + 1; j <= n; j ++)
{
if (j - ls > d)
break;
if (a[j] > a[i])
{
//cout << i << " : " << j << endl;
dp[j] = max(dp[j], dp[i] + 1);
}
else
{
if (j == n)
res = max(res, dp[i]);
ls = j;
}
}
}
res = max(res, dp[n]);
//assert(s <= res);
cout << res << endl;
}
int main()
{
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... |