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>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 201010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
ll arr[MAX];
ll dp[MAX];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, M;
ll K;
cin >> N >> M >> K;
int i, j;
for (i = 1; i <= N; i++) cin >> arr[i];
for (i = 1; i <= N; i++) {
dp[i] = dp[i - 1] + K;
ll mn, mx;
mn = mx = arr[i];
for (j = i; j > i - M; j--) {
if (!j) break;
mn = min(mn, arr[j]);
mx = max(mx, arr[j]);
dp[i] = min(dp[i], (mx - mn) * (i - j + 1) + K + dp[j - 1]);
}
}
cout << dp[N] << ln;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |