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;
vector<int> A;
vector<vector<int>> dp;
int main() {
	int N, L, R, K;
	cin >> N >> L >> R >> K;
	A = vector<int>(N + 1);
	dp = vector<vector<int>>(102, vector<int>(10205, 1e9));
	for (int i = 1; i <= N; i++)
		cin >> A[i];
	dp[0][0] = 0;
	int ans = 1e9;
	for (int i = 1; i <= N; i++) {
		vector<vector<int>> ndp(102, vector<int>(10205, 1e9));
		for (int cnt = 0; cnt <= i; cnt++) {
			int cost = abs(L + cnt - i);
			for (int last = 0; last <= K; last++) {
				ndp[cnt][last] = min(ndp[cnt][last], dp[cnt][last]);
				ndp[cnt + 1][cost + last] = min(ndp[cnt + 1][cost + last], dp[cnt][last] + A[i]);
				if (cnt+1 == R - L + 1 && cost + last <= K)
					ans = min(ans, ndp[cnt + 1][cost + last]);
			}
		}
		dp = ndp;
	}
	cout << ans;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |