#include <iostream>
#include <queue>
#include <vector>
#include <tuple>
using namespace std;
vector<int> v(2e6);
vector<bool> fil(2e6);
pair<pair<int,int>,int> opt(int i, int j) {
int best = 0;
int bestpos = j-1;
int last = j-1;
vector<int> q;
int val = 0;
for (int k = i; k < j; ++k) {
if(v[k]==-1) {
if(val>0) {
val--;
fil[k]=true;
}else {
fil[k]=false;
}
}else {
fil[k]=true;
val = max(val,v[k]);
}
}
int cnt = 0;
for (int k = j-1; k >=i; --k) {
if(v[k]==-1) {
if(!fil[k]) cnt++;
q.push_back(k);
continue;
}
int p = k+v[k];
int v = 0;
if(q.size()-cnt>best) {
best=q.size()-cnt;
bestpos=k;
}
if(!fil[k]) cnt++;
while(!q.empty() && q.back()<p) {
q.pop_back();
}
}
return {{cnt,best},bestpos};
}
int main() {
int n,d,t; cin>>n>>d>>t;
for (int i = 0; i < n; ++i) {
int x; cin>>x;
if(x>t) v[i]=-1;
else v[i]=t-x+1;
}
priority_queue<pair<int,tuple<int,int,int>>> q;
auto [a,b] = opt(0,n);
auto [l,m] = a;
int init = n-l;
q.push({m,{b,0,n}});
for (int i = 0; i < d; ++i) {
auto [a,b] = q.top(); q.pop();
auto [p,l,r] = b;
init-=a;
auto [u,v] = opt(l,p+1);
auto [u2,v2] = opt(p+1,r);
q.push({u.second,{v,l,p+1}});
q.push({u2.second,{v2,p+1,r}});
}
cout<<init<<endl;
}
# | 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... |