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;
typedef long long ll;
const int N = 300000 + 7;
int n;
int d;
int a[N];
int dp[N];
int order[N];
bool cmp(int i, int j) {
if (a[i] != a[j]) {
return a[i] > a[j];
} else {
return i < j;
}
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
//freopen ("TonyStark", "r", stdin);
cin >> n >> d;
for (int i = 1; i <= n; i++) {
cin >> a[i];
order[i] = i;
}
sort(order + 1, order + n + 1, cmp);
for (int it = 1; it <= n; it++) {
int i = order[it];
dp[i] = 0;
int bigger = 0;
for (int j = i + 1; j <= n; j++) {
dp[i] = max(dp[i], dp[j]);
if (a[j] > a[i]) {
bigger++;
} else {
bigger = 0;
}
if (bigger == d) {
break;
}
}
dp[i]++;
}
int sol = 0;
for (int i = 1; i <= n; i++) {
sol = max(sol, dp[i]);
}
cout << sol << "\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... |