Submission #697980

# Submission time Handle Problem Language Result Execution time Memory
697980 2023-02-11T17:24:04 Z sreesh Feast (NOI19_feast) C++17
0 / 100
133 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const ll INF = (ll) 1e18;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for (int& x : a) cin >> x;
    
    vector<vector<ll>> dp(n, vector<ll>(n + 1, -INF));
    vector<ll> best(n + 1, -INF);
    best[0] = 0;
    
    for (int i = 0; i < n; ++i) {
        vector<ll> new_best = best;
        for (int j = 1; j <= n; ++j) {
            // extend previous one
            if (i > 0) dp[i][j] = dp[i - 1][j] + a[i];
            // start new one here
            dp[i][j] = max(dp[i][j], best[j - 1] + a[i]);
            new_best[j] = max(new_best[j], dp[i][j]);
        }
        best = new_best;
    }

    ll ans = 0;
    // for (int i = 0; i < n; ++i) for (int j = 0; j <= min(n, k); ++j) ans = max(ans, dp[i][j]);
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Runtime error 118 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 124 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 133 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 118 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -