# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
869857 | prohacker | Holding (COCI20_holding) | C++14 | 28 ms | 30196 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 ll long long
#define ld long double
using namespace std;
const int N = 105;
const int INF = INT_MAX;
const int mod = 1e9+7;
int n,m,l,r;
int a[N];
int ans,dp[N][N][3005],f[N][N][3005],sum;
signed main()
{
if (fopen("DEBT.inp", "r")) {
freopen("DEBT.inp", "r", stdin);
freopen("DEBT.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> l >> r >> m;
m = min(m,3000);
for(int i = 1 ; i <= n ; i++) {
cin >> a[i];
if(l <= i and i <= r) {
sum += a[i];
}
}
for(int i = 1 ; i < l ; i++) {
for(int j = l ; j <= r ; j++) {
for(int k = 0 ; k <= m ; k++) {
dp[i][j][k] = max(dp[i][j][k],dp[i-1][j][k]);
dp[i][j][k] = max(dp[i][j][k],dp[i][j-1][k]);
if(k >= j-i) {
dp[i][j][k] = max(dp[i][j][k],dp[i-1][j-1][k-j+i]+a[j]-a[i]);
}
}
}
}
for(int i = n ; i > r ; i--) {
for(int j = r ; j >= l ; j--) {
for(int k = 0 ; k <= m ; k++) {
f[j][i][k] = max(f[j][i][k],f[j][i+1][k]);
f[j][i][k] = max(f[j][i][k],f[j+1][i][k]);
if(k >= i-j) {
f[j][i][k] = max(f[j][i][k],f[j+1][i+1][k+j-i]+a[j]-a[i]);
}
}
}
}
int ans = 0;
ans = max(dp[l-1][r][m],f[l][r+1][m]);
for(int i = l ; i < r ; i++) {
for(int k = 0 ; k <= m ; k++) {
ans = max(ans,dp[l-1][i][k]+f[i+1][r+1][m-k]);
}
}
cout << sum-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... |