#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, d, t;
std::cin >> n >> d >> t;
std::vector<int> a(n + 1);
for(int i = 1; i <= n; i++) {
std::cin >> a[i];
}
std::vector<std::vector<int>> dp(n + 1, std::vector<int>(d + 1, n + 1));
dp[0][0] = 0;
std::vector<int> c = a;
for(int i = 1; i <= n; i++) {
if(i)
c[i] = std::min(c[i], c[i - 1] + 1);
dp[i][0] = dp[i - 1][0];
if(c[i] <= t) {
dp[i][0] += 1;
}
}
std::vector<std::vector<int>> cost(n + 1, std::vector<int>(n + 1));
for(int i = 1; i <= n; i++) {
std::vector<int> c = a;
cost[i][i] = (c[i] <= t);
for(int j = i + 1; j <= n; j++) {
c[j] = std::min(c[j], c[j - 1] + 1);
cost[i][j] = cost[i][j - 1];
if(c[j] <= t) {
cost[i][j] += 1;
}
}
}
for(int i = 1; i <= n; i++) {
for(int c = 1; c <= d; c++) {
for(int j = i; j >= 1; j--) {
dp[i][c] = std::min(dp[i][c], dp[j - 1][c - 1] + cost[j][i]);
}
}
}
std::cout << dp[n][d];
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
//std::cin >> t;
while (t--) {
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... |