제출 #697304

#제출 시각아이디문제언어결과실행 시간메모리
697304Dan4LifeThe short shank; Redemption (BOI21_prison)C++17
0 / 100
10 ms2820 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long 
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mxN = (int)1e5+10;
const int LINF = (int)1e18;
int n, k, T, a[mxN];
int dp[mxN], dp2[mxN];
int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> k >> T; k++;
    for(int i = 1; i <= n; i++) cin >> a[i];
    int ans = 0, mn = a[1];
    for(int j = 1; j <= n; j++)
        mn = min(mn+1, a[j]), ans+=(mn<=T), dp[j] = ans;
    dp2[n] = (a[n]<=T);
    for(int i = n-1; i >= 1; i--){
        dp2[i] = dp2[i+1]+(a[i]<=T);
        if(a[i]<T){
            int r = min(n+1,i+T-a[i]+1);
            dp2[i]=max(dp2[i],dp2[r]+T-a[i]+1);
        }
    }
    for(int i = 1; i < n; i++) ans = min(ans, dp[i]+dp2[i+1]);
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...