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;
const int maxn = 3e5 + 5;
vector<int> V;
int A[maxn];
int n, D;
void nndp() {
vector<int> dp(n + 1), r(n + 1);
for(int i = 1; i <= n; ++i) {
int lst = i;
for(int j = i; j <= n; ++j) {
if(j - lst > D) break;
if(A[j] <= A[i]) lst = j;
}
r[i] = lst + D;
}
// O(n^2) dp
for(int i = 1; i <= n; ++i) {
dp[i] = 1;
for(int j = 1; j < i; ++j) {
if(r[j] >= i && A[j] < A[i])
dp[i] = max(dp[i], dp[j] + 1);
}
}
cout << *max_element(begin(dp), end(dp)) << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> D;
for(int i = 1; i <= n; ++i) {
cin >> A[i]; V.push_back(A[i]);
}
sort(begin(V), end(V));
for(int i = 1; i <= n; ++i) {
A[i] = lower_bound(begin(V), end(V), A[i]) - begin(V) + 1;
}
nndp();
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... |