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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 100010;
int arr[MAXN];
int dp[MAXN];
int n,m,k;
int rec(int x,int y,int z){
if(x>=n){
return 0;
}
if(dp[x]<1000000000){
return dp[x];
}
int maxo = arr[x];
int mino = arr[x];
int ans = 1000000000;
for(int i=x;i<min(n,x+y);i++){
//int incto = i+x;
maxo = max(maxo,arr[i]);
mino = min(mino,arr[i]);
int diff = maxo-mino;
int cost = z+(i-x+1)*diff;
int final = cost + rec(i+1,y,z);
ans = min(final,ans);
}
return dp[x] = ans;
}
int main() {
cin>>n>>m>>k;
for(int i=0;i<n;i++){
cin>>arr[i];
dp[i] = 1000000000;
}
cout<<rec(0,m,k)<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |