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;
int n,d;
int a[300005];
int dp[300005];
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>d;
for(int i=1;i<=n;i++)
cin>>a[i];
int rez=0;
for(int i=1;i<=n;i++)
{
int mxm=0,ult=i;
for(int x=i-1;x>0;x--)
{
if(ult-x > d)
break;
if(a[x]<a[i])
{
mxm = max(mxm, dp[x]);
ult = x;
}
}
dp[i]=mxm+1;
rez=max(rez,dp[i]);
}
cout<<rez;
return 0;
}
/**
dp[i] = scorul maxim care se poate obtine daca ultimul element care creste scorul se afla pe pozitia i
dp[i] = max(dp[x]) + 1, a[x] < a[i], distanta dintre oricare 2 pozitii consecutive cu numere < a[i] este maxim d
*/
# | 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... |