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;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 2e6+100;
int N, D, T, a[MAXN];
vector<int> g[MAXN];
void compute_time(){
    stack<int> st;
    rep(i, 0, N - 1){
        while(!st.empty()){
            int j = st.top();
            if(a[j] + i - j > T) st.pop();
            else break;
        }
        if(a[i] <= T){
            g[i].pb(i);
        } else{
            if(!st.empty()) g[st.top()].pb(i);
        }
        st.push(i);
    }
}
const int MAXD = 4000+100;
class SegmentTree{
public:
    vector<int> st, lazy;
    void build(int n){
        st = lazy = vector<int>(4 * n);
    }
    void push(int i){
        if(lazy[i]){
            int cl = 2 * i + 1, cr = 2 * i + 2;
            st[cl] += lazy[i], lazy[cl] += lazy[i];
            st[cr] += lazy[i], lazy[cr] += lazy[i];
            lazy[i] = 0;
        }
    }
    void merge(int i){
        int cl = 2 * i + 1, cr = 2 * i + 2;
        st[i] = min(st[cl], st[cr]);
    }
    void add(int i, int l, int r, int ql, int qr, int k){
        if(ql <= l && r <= qr){
            st[i] += k, lazy[i] += k; return;
        }
        if(qr < l || ql > r) return;
        push(i);
        int m = (l + r) / 2;
        add(2 * i + 1, l, m, ql, qr, k);
        add(2 * i + 2, m + 1, r, ql, qr, k);
        merge(i);
    }
    int query(int i, int l, int r, int ql, int qr){
        if(ql <= l && r <= qr){
            return st[i];
        }
        if(qr < l || ql > r) return INT_MAX;
        push(i);
        int m = (l + r) / 2;
        int ans1 = query(2 * i + 1, l, m, ql, qr);
        int ans2 = query(2 * i + 2, m + 1, r, ql, qr);
        return min(ans1, ans2);
    }
} st[MAXD];
void compute_dp(){
    rep(d, 0, D){
        st[d].build(N + 1);
    }
    per(i, N - 1, 0){
        for(int j : g[i]){
            rep(d, 0, D){
                st[d].add(0, 0, N, j + 1, N, +1);
            }
        }
        int val = st[0].query(0, 0, N, N, N);
        st[0].add(0, 0, N, i, i, val);
        rep(d, 1, D){
            val = st[d - 1].query(0, 0, N, i + 1, N);
            st[d].add(0, 0, N, i, i, val);
        }
    }
}
void solve(){
    cin >> N >> D >> T;
    rep(i, 0, N - 1) cin >> a[i];
    compute_time();
    compute_dp();
    cout << st[D].query(0, 0, N, 0, 0);
}
int main(){
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    solve();
    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... |