Skip to content

Instantly share code, notes, and snippets.

@gedorinku
Created February 16, 2016 09:41
Show Gist options
  • Save gedorinku/8b992f34c78a2b629ecb to your computer and use it in GitHub Desktop.
Save gedorinku/8b992f34c78a2b629ecb to your computer and use it in GitHub Desktop.
JOI2016本選
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PB push_back
#define PPB pop_back
typedef pair<int, int> pii;
static const int INF = 1LL<<61;
static const int MAX_N = 20005;
static const int MAX_M = 1005;
int n, m, k, dp[MAX_N], A[MAX_N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 0; i < n; ++i) {
cin >> A[i];
}
fill(dp, dp + MAX_N, INF);
dp[0] = 0;
for (int i = 0; i < n; ++i) {
int tmax = 0, tmin = INF;
for (int j = 1; j <= m && i + j <= n; ++j) {
tmax = max(tmax, A[i + j - 1]);
tmin = min(tmin, A[i + j - 1]);
dp[i + j] = min(dp[i + j], dp[i] + (k + j * (tmax - tmin)));
}
}
cout << dp[n] << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment