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;
#define int long long
int dp[300000],minm[300000],a[300000];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1,n,d;
// cin >> t;
while (t--){
cin >> n >> d;
for (int i = 0; i < n; i++){
cin >> a[i];
}
int ans = 1;
dp[n-1] = 1;
minm[n-1] = a[n-1];
for (int i = n-2; i >= 0; i--){
dp[i] = 1;
minm[i] = a[i];
int j = i+1,cur=0;
while(j < n && cur < d){
if (a[i] < minm[j] && dp[i] < dp[j]+1){
dp[i] = dp[j]+1;
minm[i] = a[i];
// cout << "a " << dp[i] << " " << maxm[i] << "\n";
}
/* else if (dp[i] < dp[j]){
dp[i] = dp[j];
minm[i] = minm[j];
// cout << "b " << dp[i] << " " << maxm[i] << "\n";
}*/
j++;
cur++;
}
ans = max(ans,dp[i]);
//cout << i+1 << " " << dp[i] << "\n\n";
}
cout << ans << "\n";
//cout << dp[n-1] << "\n";
}
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... |