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;
typedef long long ll;
typedef long double ld;
ll dp[100005];
ll a[100005];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
ll n, m, k;
cin >> n >> m >> k;
for(int i=1; i<=n; i++){
cin >> a[i];
ll mn = a[i], mx = a[i];
dp[i] = dp[i-1] + k;
for(int j=i-1; j>=1 && i-j+1<=m; j--){
mn = min(mn, a[j]);
mx = max(mx, a[j]);
dp[i] = min(dp[i], dp[j-1] + k + (i-j+1)*(mx-mn));
}
}
cout << dp[n] << endl;
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... |