Submission #868258

# Submission time Handle Problem Language Result Execution time Memory
868258 2023-10-31T01:32:42 Z hungnt Holding (COCI20_holding) C++14
22 / 110
1 ms 4560 KB
#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]);
                    MAX(dp[i][c][j], dp[i - 1][c - i + j][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
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4560 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4560 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Incorrect 1 ms 4440 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4560 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Incorrect 1 ms 4440 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4560 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Incorrect 1 ms 4440 KB Output isn't correct
9 Halted 0 ms 0 KB -