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<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 3e5 + 7, N2 = 400 + 2;
int n, d;
int a[N];
// dp[i][j] -> dp[k][a[j] > a[k] ? j : k]
void maximize(int &a, int b) { if (a < b) a = b; }
int dp[N2][N2];
void subtask2() {
for (int i = 0; i < n; ++i)
for (int j = 0; j <= i; ++j)
for (int k = i + 1; k <= min(n, i + d); ++k) {
if (a[j] < a[k])
maximize(dp[k][k], dp[i][j] + 1);
else maximize(dp[k][j], dp[i][j]);
}
int ans(0);
for (int i = 1; i <= n; ++i)
maximize(ans, dp[n][i]);
cout << ans << '\n';
}
int main() {
cin.tie(NULL)->sync_with_stdio(false);
cin >> n >> d;
for (int i = 1; i <= n; ++i) cin >> a[i];
a[0] = -1;
if (n <= 400) subtask2();
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
# | 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... |