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;
const int N=2000050;
int n,d,t,a[N],par[N],diff[N],ans,pt,mx[N],mv[N];
bool del[N];
vector<int> stk,nde[N],ch[N];
int main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n>>d>>t;
ans=pt=n;
for (int i=1;i<=n;i++){
cin>>a[i];
diff[i]+=diff[i-1];
if (a[i]<=t) diff[i]++,diff[min(i+t-a[i]+1,N-2)]--;
else if (diff[i]) par[i]=i;
else ans--;
}
for (int i=1;i<=n;i++){
while (stk.size()){
if (a[stk.back()]<=t){
if (stk.back()+t-a[stk.back()]<i) stk.pop_back();
else break;
}else if (a[i]>t&&diff[i]){
par[stk.back()]=i;
ch[i].push_back(stk.back());
stk.pop_back();
}else break;
}
stk.push_back(i);
}
//for (int i=1;i<=n;i++) cout<<par[i]<<"\n";
for (int i=1;i<=n;i++){
if (a[i]<=t||!diff[i]) continue;
mx[i]=1;
for (int j:ch[i]){
if (j==i) continue;
if (mx[j]+1>mx[mv[i]]) mx[i]=mx[j]+1,mv[i]=j;
}
nde[mx[i]].push_back(i);
}
//for (int i=1;i<=n;i++) cout<<mx[i]<<" "<<mv[i]<<"\n";
while (pt){
for (int j:nde[pt]){
if (del[j]) continue;
//cout<<j<<" "<<pt<<"!\n";
if (!d) goto done;
ans-=pt;
d--;
for (int k=j;k;k=mv[k]){
del[k]=1;
}
}
pt--;
}
done:;
cout<<ans<<"\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... |