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 INF=INT_MAX/2;
const int N=2e6+5;
int n,d,t,ans;
int a[N],pre[N],par[N],dep[N],deep[N],cnt[N];
stack<pair<int,int>> s,st;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> d >> t;
for(int i=1;i<=n;i++)cin >> a[i];
s.emplace(-INF,0);
for(int i=1;i<=n;i++){
int x=min(a[i],t)-i;
while(s.top().first>x)s.pop();
if(a[i]>t)pre[i]=s.top().second;
else ans++;
s.emplace(a[i]-i,i);
}
for(int i=1;i<=n;i++)if(pre[i]){
ans++;
while(!st.empty()&&st.top().first>=pre[i]){
par[st.top().second]=i;
st.pop();
}
st.emplace(pre[i],i);
}
for(int i=1;i<=n;i++)if(pre[i]){
cnt[dep[deep[i]]]--;
dep[i]=dep[deep[i]]+1;
cnt[dep[i]]++;
if(dep[i]>dep[deep[par[i]]])deep[par[i]]=i;
}
for(int i=n;i>=1;i--)while(cnt[i]--&&d-->0)ans-=i;
cout << ans;
}
# | 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... |