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>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
int dp[1000][1000];
signed main() {
int n, d;
cin >> n >> d;
vector<int> v(n+1); set<int> s;
for(int i=1; i<=n; i++) cin >> v[i], s.insert(v[i]);
vector<int> comp(s.begin(), s.end());
for(int i=1; i<=n; i++) v[i] = lower_bound(comp.begin(), comp.end(), v[i]) - comp.begin();
int m = s.size();
for(int i=1; i<=n; i++) {
//prv element
dp[i][v[i]] = 1;
//make this the new maximum
for(int k=i-1; k>=max(1, i-d); k--)
for(int j=0; j<v[i]; j++) dp[i][v[i]] = max(dp[i][v[i]], dp[k][j] + 1);
//dont make this the new maximum
for(int k=i-1; k>=max(1, i-d); k--)
for(int j=v[i]; j<m; j++) dp[i][j] = max(dp[i][j], dp[k][j]);
}
int ans = 0;
for(int i=0; i<m; i++) ans = max(ans, dp[n][i]);
cout << ans << '\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... |