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;
using ll = long long;
inline void fastio();
ll n, m, k;
ll a[20005], dp[20005];
int main() {
fastio();
cin >> n >> m >> k;
for (ll i = 1; i <= n; i++) {
cin >> a[i];
dp[i] = 9e18;
}
for (ll i = 1; i <= n; i++) {
ll mins = a[i], maxs = a[i];
for (ll j = 1; j <= i and j <= m; j++) {
mins = min(mins, a[i - j + 1]);
maxs = max(maxs, a[i - j + 1]);
dp[i] = min(dp[i], dp[i - j] + j * (maxs - mins) + k);
}
}
cout << dp[n] << '\n';
}
inline void fastio() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(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... |