# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
868254 | lmToT27 | Holding (COCI20_holding) | C++11 | 40 ms | 204116 KiB |
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;
int dpL[102][102][2502], dpR[102][102][2502], ans = 1e9, tong;
int n, a[102], L, R, K;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("TASK.INP", "r")) {
freopen("TASK.INP", "r", stdin);
freopen("TASK.OUT", "w", stdout);
}
memset(dpL, 0x3f, sizeof dpL);
memset(dpR, 0x3f, sizeof dpR);
cin >> n >> L >> R >> K;
K = min(K, n * n / 4);
dpL[L][L - 1][0] = 0;
dpR[R + 1][R][0] = 0;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = L; i <= R; i++) {
for (int j = L; j >= 1; j--) {
for (int TIME = 0; TIME <= K; TIME++) {
dpL[j][i][TIME] = min(dpL[j + 1][i][TIME], dpL[j][i - 1][TIME] + a[i]);
if (TIME - i + j >= 0)
dpL[j][i][TIME] = min(dpL[j][i][TIME], dpL[j + 1][i - 1][ TIME - i + j] + a[j]);
}
}
}
for (int i = R; i >= L; i--) {
for (int j = R; j <= n; j++) {
for (int TIME = 0; TIME <= K; TIME++) {
dpR[i][j][TIME] = min(dpR[i][j - 1][TIME], dpR[i + 1][j][TIME] + a[i]);
if (TIME - j + i >= 0)
dpR[i][j][TIME] = min(dpR[i][j][TIME], dpR[i + 1][j - 1][TIME - j + i] + a[j]);
}
}
}
for (int TIME = 0; TIME <= K; TIME++)
dpL[1][L - 1][TIME] = dpR[R + 1][n][TIME] = 0;
for (int i = L - 1; i <= R; i++)
for (int TIME = 0; TIME <= K; TIME++)
ans = min(ans, dpL[1][i][TIME] + dpR[i + 1][n][K - TIME]);
cout << ans;
return 0;
}
Compilation message (stderr)
# | 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... |