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 int long long
#define f first
#define s second
const int N = 2e4 + 69;
int dp[N], n, a[N], k, m;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> m >> k;
for (int i = 1;i <= n;i++) {
cin >> a[i];
dp[i] = 1e18;
}
for (int i = 1;i <= n;i++) {
int mx = a[i], mn = a[i];
for (int j = i - 1;j >= max(0ll, i - m);j--) {
dp[i] = min(dp[i], dp[j] + k + (i - j) * (mx - mn));
mx = max(mx, a[j]);
mn = min(mn, a[j]);
}
}
cout << dp[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... |