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 pozs[300005];
int dp[300005];
void calc_pozs()
{
for(int i=1;i<=n;i++)
{
int ult=i;
pozs[i]=i;
for(int j=i-1;j>0;j--)
{
if(ult-j>d)
break;
if(a[j]<a[i])
{
ult=j;
pozs[i]=j;
}
}
}
}
pair<int,int> ord2[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];
calc_pozs();
for(int i=1;i<=n;i++)
{
ord2[i]={a[i],-i};
}
sort(ord2+1,ord2+1+n);
int cur;
for(int i=1;i<=n;i++)
{
cur = -ord2[i].second;
for(int j=pozs[cur];j<cur;j++)
dp[cur] = max(dp[cur], dp[j]);
dp[cur]++;
}
int rez=1;
for(int i=1;i<=n;i++)
rez=max(rez,dp[i]);
cout<<rez;
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... |