#include <algorithm>
#include <iostream>
using namespace std;
const int N = 20000;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
int aa[N + 1];
long long dp[N + 1];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
int n, m, c; cin >> n >> m >> c;
for (int i = 1; i <= n; i++) {
cin >> aa[i];
long long x = INF;
for (int l = aa[i], r = aa[i], j = i; j > i - m && j; j--) {
l = min(l, aa[j]), r = max(r, aa[j]);
x = min(x, dp[j - 1] + c + (long long) (i - j + 1) * (r - l));
}
dp[i] = x;
}
cout << dp[n] << '\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... |