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 main() {
cin.tie(0)->sync_with_stdio(0);
int n, d;
cin >> n >> d;
vector<int> A(n);
for (int i=0; i<n; i++) cin >> A[i];
if (d == 1) {
int ans = 1, curr = 1, prev = A[n-1];
for (int i=n-2; i>=0; i--) {
if (A[i] < prev) {
curr += 1;
} else if (A[i] > prev) {
curr = 1;
}
prev = A[i];
ans = max(ans, curr);
}
cout << ans << "\n";
} else {
vector<int> dp(n,1);
int ans = 0;
for (int i=0; i<n; i++) {
for (int j=i-d; j<i; j++) {
if (A[j] < A[i]) {
dp[i] = max(dp[i], dp[j]+1);
}
if (A[j] == A[i]) {
dp[i] = max(dp[i], dp[j]);
}
}
ans = max(ans, dp[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... |