Submission #1035509

# Submission time Handle Problem Language Result Execution time Memory
1035509 2024-07-26T11:39:31 Z Jethro Holding (COCI20_holding) C++14
0 / 110
2 ms 344 KB
//Written by: Jethro_
//----------------------
#include <bits/stdc++.h>
using namespace std;

int n, l, r, k;

void solve() {
    cin >> n >> l >> r >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

	vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>((r - l + 1) + 1, vector<int>(k + 1, 1e9)));

    int res = 1e9;
    
    dp[0][l - 1][0] = 0;

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= k; ++j) {
            dp[i][l - 1][j] = 0;
        }
    }
    for (int i = 1; i <= n; ++i) {  

        for (int j = l; j <= r; ++j) {

            for (int p = 0; p <= k; ++p) {
                dp[i][j][p] = dp[i - 1][j][p];
                if (p - abs(j - i) >= 0) {
                    dp[i][j][p] = min({dp[i][j][p], dp[i - 1][j - 1][p - abs(j - i)] + a[i]});
                }
                
                if (j == r) res = min(res, dp[i][r][p]);

            }
            

        }
    }


    cout << res;
}
int main() {

    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    solve();

}


//dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j - 1][k], dp[i - 1][j - 1][k + abs(j - i)] - a[i] + a[j]);
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -