#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define ll long long
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll,ll>
#define all(x) (x).begin(),(x).end()
struct segTree {
struct node {
int mn=1e9;
int lzy=0;
node(int _mn=1e9): mn(_mn) {}
};
int sze;
vector<node> nodes;
node unite(node a, node b) {
return min(a.mn,b.mn);
}
void push(int v, int tl, int tr) {
nodes[v].mn+=nodes[v].lzy;
if (tl!=tr) {
nodes[2*v].lzy+=nodes[v].lzy;
nodes[2*v+1].lzy+=nodes[v].lzy;
}
nodes[v].lzy=0;
}
segTree(int n): sze(n) {
nodes.resize(4*n);
}
node get(int l, int r, int v, int tl, int tr) {
push(v,tl,tr);
if (l<=tl && tr<=r) {
return nodes[v];
}
if (tr<l || r<tl) {
return node();
}
int tm=tl+(tr-tl)/2;
return unite(get(l,r,2*v,tl,tm),get(l,r,2*v+1,tm+1,tr));
}
node get(int l, int r) {
return get(l,r,1,0,sze-1);
}
void update1(int l, int r, int add, int v, int tl, int tr) {
push(v,tl,tr);
if (l<=tl && tr<=r) {
nodes[v].lzy+=add;
push(v,tl,tr);
return;
}
if (tr<l || r<tl) {
return;
}
int tm=tl+(tr-tl)/2;
update1(l,r,add,2*v,tl,tm);
update1(l,r,add,2*v+1,tm+1,tr);
nodes[v]=unite(nodes[2*v],nodes[2*v+1]);
}
void update1(int l, int r, int add) {
update1(l,r,add,1,0,sze-1);
}
void update2(int ind, int val, int v, int tl, int tr) {
push(v,tl,tr);
if (tl==tr) {
nodes[v]=min(val,nodes[v].mn);
return;
}
if (tr<ind || ind<tl) {
return;
}
int tm=tl+(tr-tl)/2;
update2(ind,val,2*v,tl,tm);
update2(ind,val,2*v+1,tm+1,tr);
nodes[v]=unite(nodes[2*v],nodes[2*v+1]);
}
void update2(int ind, int val) {
update2(ind,val,1,0,sze-1);
}
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n,d,t;
cin >> n >> d >> t;
vi a(n);
int cnt=0;
for (int i=0; i<n; i++) {
cin >> a[i];
if (a[i]<=t) {
cnt++;
}
}
vector<segTree> data(d+1,segTree(n+1));
data[0].update2(0,0);
for (int i=0; i<n; i++) {
for (int k=d; k>=0; k--) {
if (a[i]>t) {
data[k].update1(i+1,n,1);
if (k<d) {
data[k+1].update2(0,data[k].get(0,n).mn);
}
}
else {
data[k].update2(min(n,i+t-a[i]+1),data[k].get(0,n).mn);
}
}
}
int ans=n;
for (int k=0; k<=d; k++) {
ans=min(ans,data[k].get(0,n).mn);
}
cout << ans+cnt << '\n';
/*vector<vector<vi>> dp(n+1,vector<vi>(n+1,vi(d+1,1e9)));
dp[0][0][0]=0;
for (int i=0; i<n; i++) {
for (int j=0; j<=n; j++) {
for (int k=0; k<=d; k++) {
int jj=max(j,min(n,i+t-a[i]+1));
dp[i+1][jj][k]=min(dp[i+1][jj][k],dp[i][j][k]+(j>i && a[i]>t));
if (k<d) {
dp[i][j][k+1]=min(dp[i][j][k+1],dp[i][j][k]);
}
if (k<d && a[i]>t) {
dp[i+1][0][k+1]=min(dp[i+1][0][k+1],dp[i][j][k]);
}
}
}
}
int ans=n;
for (int j=0; j<=n; j++) {
ans=min(ans,dp[n][j][d]);
}
cout << ans+cnt << '\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... |