제출 #1271411

#제출 시각아이디문제언어결과실행 시간메모리
1271411kaiboy오렌지 출하 (JOI16_ho_t1)C++20
100 / 100
30 ms584 KiB
#include <algorithm>
#include <iostream>

using namespace std;

const       int   N = 20000;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;

int aa[N + 1];
long long dp[N + 1];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	int n, m, c; cin >> n >> m >> c;
	for (int i = 1; i <= n; i++) {
		cin >> aa[i];
		long long x = INF;
		for (int l = aa[i], r = aa[i], j = i; j > i - m && j; j--) {
			l = min(l, aa[j]), r = max(r, aa[j]);
			x = min(x, dp[j - 1] + c + (long long) (i - j + 1) * (r - l));
		}
		dp[i] = x;
	}
	cout << dp[n] << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...