이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// author: erray
#include <bits/stdc++.h>
#ifdef DEBUG
#include "debug.h"
#else
#define debug(...) void(37)
#endif
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, L, R, K;
cin >> N >> L >> R >> K;
--L, --R;
vector<int> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
const int inf = int(1e9);
int S = R - L + 1;
vector<vector<int>> dp(S + 1, vector<int>(K + 1, inf));
dp[0][0] = 0;
for (int i = 0; i < N; ++i) {
vector<vector<int>> new_dp = dp;
for (int j = 0; j < S; ++j) {
int cost = abs(L + j - i);
for (int c = 0; c + cost <= K; ++c) {
int& go = new_dp[j + 1][cost + c];
int& from = dp[j][c];
go = min(go, from + A[i]);
}
}
swap(dp, new_dp);
debug(dp);
}
cout << (*min_element(dp[S].begin(), dp[S].end())) << '\n';
}
# | 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... |