Submission #543997

# Submission time Handle Problem Language Result Execution time Memory
543997 2022-03-31T19:19:39 Z AlperenT Holding (COCI20_holding) C++17
110 / 110
169 ms 16516 KB
#include <bits/stdc++.h>

using namespace std;

const long long N = 100 + 5, K = 1e4 + 5, INF = 2e18 + 5;

long long n, l, r, k, arr[N], dp[N][K], prefix[N][K], suffix[N][K], ans = INF;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    cin >> n >> l >> r >> k;

    for(int i = 1; i <= n; i++) cin >> arr[i];

    for(int i = 0; i < N; i++){
        for(int j = 0; j < K; j++){
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    for(int i = 1; i <= n; i++){
        for(int rcnt = i; rcnt >= 0; rcnt--){
            for(int j = k; j >= 0; j--){
                if(rcnt > 0 && j >= rcnt) dp[rcnt][j] = min(dp[rcnt][j - rcnt], dp[rcnt - 1][j] + arr[i]);
                else if(rcnt > 0 && j < rcnt) dp[rcnt][j] = dp[rcnt - 1][j] + arr[i];
                else if(j >= rcnt) dp[rcnt][j] = dp[rcnt][j - rcnt];
            }
        }

        if(i >= l && i <= r){
            for(int j = 0; j <= k; j++) prefix[i][j] = dp[i - l + 1][j];
            for(int j = 1; j <= k; j++) prefix[i][j] = min(prefix[i][j], prefix[i][j - 1]);
        }
    }

    for(int i = 0; i < N; i++){
        for(int j = 0; j < K; j++){
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    for(int i = n; i >= 1; i--){
        for(int rcnt = i; rcnt >= 0; rcnt--){
            for(int j = k; j >= 0; j--){
                if(rcnt > 0 && j >= rcnt) dp[rcnt][j] = min(dp[rcnt][j - rcnt], dp[rcnt - 1][j] + arr[i]);
                else if(rcnt > 0 && j < rcnt) dp[rcnt][j] = dp[rcnt - 1][j] + arr[i];
                else if(j >= rcnt) dp[rcnt][j] = dp[rcnt][j - rcnt];
            }
        }

        if(i >= l && i <= r){
            for(int j = 0; j <= k; j++) suffix[i][j] = dp[r - i + 1][j];
            for(int j = 1; j <= k; j++) suffix[i][j] = min(suffix[i][j], suffix[i][j - 1]);
        }
    }

    for(int i = l - 1; i <= r; i++){
        for(int j = 0; j <= k; j++){
            ans = min(ans, prefix[i][j] + suffix[i + 1][k - j]);
        }
    }

    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8532 KB Output is correct
2 Correct 4 ms 8516 KB Output is correct
3 Correct 4 ms 8660 KB Output is correct
4 Correct 5 ms 8660 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 5 ms 8660 KB Output is correct
7 Correct 8 ms 9556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8532 KB Output is correct
2 Correct 4 ms 8516 KB Output is correct
3 Correct 4 ms 8660 KB Output is correct
4 Correct 5 ms 8660 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 5 ms 8660 KB Output is correct
7 Correct 8 ms 9556 KB Output is correct
8 Correct 5 ms 8660 KB Output is correct
9 Correct 5 ms 8660 KB Output is correct
10 Correct 5 ms 8788 KB Output is correct
11 Correct 6 ms 8788 KB Output is correct
12 Correct 5 ms 8916 KB Output is correct
13 Correct 45 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8532 KB Output is correct
2 Correct 4 ms 8516 KB Output is correct
3 Correct 4 ms 8660 KB Output is correct
4 Correct 5 ms 8660 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 5 ms 8660 KB Output is correct
7 Correct 8 ms 9556 KB Output is correct
8 Correct 5 ms 8660 KB Output is correct
9 Correct 5 ms 8660 KB Output is correct
10 Correct 5 ms 8788 KB Output is correct
11 Correct 6 ms 8788 KB Output is correct
12 Correct 5 ms 8916 KB Output is correct
13 Correct 45 ms 12628 KB Output is correct
14 Correct 5 ms 8532 KB Output is correct
15 Correct 7 ms 8532 KB Output is correct
16 Correct 5 ms 8532 KB Output is correct
17 Correct 5 ms 8608 KB Output is correct
18 Correct 5 ms 8648 KB Output is correct
19 Correct 45 ms 12500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8532 KB Output is correct
2 Correct 4 ms 8516 KB Output is correct
3 Correct 4 ms 8660 KB Output is correct
4 Correct 5 ms 8660 KB Output is correct
5 Correct 4 ms 8532 KB Output is correct
6 Correct 5 ms 8660 KB Output is correct
7 Correct 8 ms 9556 KB Output is correct
8 Correct 5 ms 8660 KB Output is correct
9 Correct 5 ms 8660 KB Output is correct
10 Correct 5 ms 8788 KB Output is correct
11 Correct 6 ms 8788 KB Output is correct
12 Correct 5 ms 8916 KB Output is correct
13 Correct 45 ms 12628 KB Output is correct
14 Correct 5 ms 8532 KB Output is correct
15 Correct 7 ms 8532 KB Output is correct
16 Correct 5 ms 8532 KB Output is correct
17 Correct 5 ms 8608 KB Output is correct
18 Correct 5 ms 8648 KB Output is correct
19 Correct 45 ms 12500 KB Output is correct
20 Correct 11 ms 8660 KB Output is correct
21 Correct 14 ms 8556 KB Output is correct
22 Correct 6 ms 8532 KB Output is correct
23 Correct 64 ms 8672 KB Output is correct
24 Correct 10 ms 9300 KB Output is correct
25 Correct 169 ms 16516 KB Output is correct