# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1075637 | tradz | Holding (COCI20_holding) | C++14 | 103 ms | 204616 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>
#define For(i,a,b) for(int i = a; i <= b; i++)
#define Ford(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define RRH(v) v.resize(unique(all(v)) - v.begin())
using namespace std;
const int N = 1e6+7;
const int M = 1e9+7;
const ll oo = 3e18;
int n, l, r, k;
int a[N];
int dpL[102][102][2507];
int dpR[102][102][2507];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
#define TASK ""
if (fopen (".inp", "r")) {
freopen (".inp", "r", stdin);
freopen (".out", "w", stdout);
}
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
cin >> n >> l >> r >> k;
memset(dpL, 0, sizeof dpL);
memset(dpR, 0, sizeof dpR);
For (i, 1, n) cin >> a[i];
k = min(k, n * n / 4);
int sum = 0;
for (int i = l; i <= r; i++) sum += a[i];
for (int i = 1; i < l; i++) {
for (int j = l; j <= r; j++) {
for (int h = 0; h <= k; h++) {
dpL[i][j][h] = max(dpL[i - 1][j][h], dpL[i][j - 1][h]);
if (h >= (j - i)) dpL[i][j][h] = max(dpL[i][j][h], dpL[i - 1][j - 1][h - j + i] + a[j] - a[i]);
}
}
}
for (int i = n; i > r; i--) {
for (int j = r; j >= l; j--) {
for (int h = 0; h <= k; h++) {
dpR[j][i][h] = max(dpR[j + 1][i][h], dpR[j][i + 1][h]);
if (h >= (i - j)) dpR[j][i][h] = max(dpR[j][i][h], dpR[j + 1][i + 1][h - i + j] + a[j] - a[i]);
}
}
}
int ans = 0;
ans = max(dpL[l - 1][r][k], dpR[l][r + 1][k]);
for (int i = l; i <= r; i++) {
for (int h = 0; h <= k; h++) {
ans = max(ans, dpL[l - 1][i][h] + dpR[i + 1][r + 1][k - h]);
}
}
cout << sum - ans << '\n';
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... |