#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, d; cin>>n>>d;
vector<int> a(n + 1);
vector<pii> all;
for (int i = 1; i <= n; i++){
cin>>a[i];
all.pb({a[i], i});
}
sort(all.begin(), all.end());
int i = 0, m = 0;
while (i < n){
int j = i; m++;
while (j < n && all[i].ff == all[j].ff){
a[all[j].ss] = m;
j++;
}
i = j;
}
vector<int> t(n + 1), x(n + 1);
for (int i = 1; i <= n; i++){
int v = (t[a[i] - 1] >= (i - d)) ? (x[a[i] - 1] + 1) : 1;
int j = a[i] + 1;
while (j <= m && t[j] < (i - d)) j++;
while (j <= m && x[j] < v) j++;
for (int t = a[i]; t < j; t++) x[t] = v;
for (int j = a[i]; j <= m; j++){
t[j] = i;
}
}
cout<<x[m]<<"\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... |