Submission #697979

# Submission time Handle Problem Language Result Execution time Memory
697979 2023-02-11T17:21:45 Z sreesh Feast (NOI19_feast) C++17
41 / 100
122 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 117 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 111 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 122 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 800 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 800 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 23 ms 29956 KB Output is correct
22 Correct 26 ms 29524 KB Output is correct
23 Correct 24 ms 30036 KB Output is correct
24 Correct 23 ms 29976 KB Output is correct
25 Correct 26 ms 31676 KB Output is correct
26 Correct 26 ms 31472 KB Output is correct
27 Correct 26 ms 31560 KB Output is correct
28 Correct 25 ms 31316 KB Output is correct
29 Correct 27 ms 30840 KB Output is correct
30 Correct 23 ms 29816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 117 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -