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;
using ll = long long;
int n, d;
int a[(int)3e5 + 10];
const int N = 7e3 + 10;
bool f[N][N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> d;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= n; i++) {
int lst = i;
bool flag = 1;
for(int j = i + 1; j <= n; j++) {
if(!flag) break;
if(j - lst <= d)
f[i][j] = 1;
if(a[j] <= a[i]) flag &= (j - lst <= d), lst = j;
}
}
vector<int> dp(n + 1, 1);
dp[1] = 1;
for(int i = 1; i <= n; i++) {
for(int j = i + 1; j <= n && f[i][j]; j++)
if(a[j] > a[i]) dp[j] = max(dp[j], dp[i] + 1);
}
int res = 0;
for(int i = 1; i <= n; i++) {
res = max(res, dp[i]);
}
cout << res;
}
# | 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... |