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;
using ld = long double;
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define int long long
void solve(){
int n, m, k;
cin >> n >> m >> k;
int a[n];
int dp[n+1]={0};
for(int i=0; i< n; i++)cin >> a[i];
for(int i=1; i<=n; i++){
dp[i]=2e18;
int mx=a[i-1];
int mn=a[i-1];
for(int j=i; j>=max(1ll, i-m+1); j--){
mx=max(mx, a[j-1]);
mn=min(mn, a[j-1]);
dp[i]=min(dp[i], k+dp[j-1]+(mx-mn)*(i-j+1));
}
}
cout << dp[n] << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |