Submission #697978

#TimeUsernameProblemLanguageResultExecution timeMemory
697978sreeshFeast (NOI19_feast)C++17
41 / 100
131 ms262148 KiB
#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 <= k; ++j) ans = max(ans, dp[i][j]); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...