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;
#define ll long long
const int INF = 3e5+5;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, d; cin >> n >> d;
vector<int> a(n), b(n), r(n);
map<int,int> compress;
vector<int> dp(n+1, 1);
for (int i = 0; i < n; ++i) {
cin >> a[i];
b[i] = a[i];
}
sort(b.begin(), b.end());
for (int i =0; i < n; ++i) {
if (!compress[b[i]]) {
compress[b[i]] = compress.size();
}
}
for (int i = 0; i < n; ++i) {
a[i] = compress[a[i]];
}
for (int i = 0; i < n; ++i) {
int cnt = 0;
for (int j = i + 1; j < n; ++j) {
if (a[j] <= a[i]) cnt = 0;
else {
cnt++;
if (cnt == d+1) {
r[i] = j;
break;
}
}
}
if (cnt <= d) r[i] = n-1;
//cout << r[i] << " ";
}
//cout << endl;
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < r[i]; ++j) {
if (a[i] < a[j]) {
dp[j] = max(dp[j], dp[i] + 1);
}
}
ans = max(ans, dp[i]);
//cout << 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... |