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;
const int N = 52;
int n, L, R, k;
int a[102];
int dp[N][1500][N];
void MAX(int &A, int B)
{
if(A < B) A = B;
}
void sub2(int L)
{
k = min(k, n * n / 2);
for(int i = L; i <= R; i++)
for(int c = 1; c <= k; c++)
for(int j = 1; j <= L - 1; j++)
dp[i][c][j] = 0;
int ans = 0;
for(int i = L; i <= R; i++)
for(int c = 1; c <= k; c++)
for(int j = L - 1; j > 0; j--)
{
MAX(dp[i][c][j], dp[i - 1][c][j]);
MAX(dp[i][c][j], dp[i][c][j - 1]);
if(c - i + j >= 0)
{
MAX(dp[i][c][j], dp[i - 1][c - i + j][j - 1] + a[i] - a[j]);
// cout << i << " " << j << " " << c << " " << dp[i][c][j] << "\n";
}
ans = max(ans, dp[i][c][j]);
}
// cout << ans << "\n";
for(int i = L; i <= R; i++) ans -= a[i];
cout << -ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> L >> R >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
if(R == n)
{
sub2(L);
return 0;
}
}
# | 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... |