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;
constexpr int LIM = 300'000;
int dp[LIM + 10];
int tab[LIM + 10];
int ran[LIM + 10];
int main() {
int n, d;
cin >> n >> d;
for(int i = 1; i <= n; i++) {
cin >> tab[i];
}
for(int i = 1; i <= n; i++) {
int akt = i;
for(int j = i + 1; j <= n; j++) {
if(j - akt > d) {
break;
}
if(tab[j] <= tab[i]) {
akt = j;
}
ran[i] = j;
}
}
for(int i = 1; i <= n; i++) {
dp[i] = 1;
for(int j = i - 1; j >= 1; j--) {
if(tab[j] < tab[i] && ran[j] >= i) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
}
int ans = 0;
for(int j = 1; j <= n; j++) {
if(ran[j] == n) {
ans = max(ans, dp[j]);
}
}
cout << ans << '\n';
}
# | 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... |