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;
ll N, M, K;
ll A[20005], D[20005];
int main(){
cin.tie(0) -> sync_with_stdio(false);
cin >> N >> M >> K;
for(ll i = 1; i <= N; i++){
cin >> A[i];
}
for(ll i = 1; i <= N; i++){
D[i] = 1e18;
ll x = A[i], y = A[i], c = 0;
for(ll j = i; j >= max(1LL, i - M + 1); j--){
x = min(x, A[j]), y = max(y, A[j]), c++;
D[i] = min(D[i], D[j - 1] + K + c * (y - x));
}
}
cout << D[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... |