#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> dp(n + 1, 1e18);
dp[0] = 0;
for(int i = 1; i <= n; i++) {
int mx = 0;
int mn = 1e18;
for(int j = i; j >= 1; j--) {
if(i - j + 1 > m) {
break;
}
mx = max(mx, a[j]);
mn = min(mn, a[j]);
dp[i] = min(dp[i], dp[j - 1] + (i - j + 1) * (mx - mn) + k);
}
}
cout << dp[n];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |