Submission #1025648

#TimeUsernameProblemLanguageResultExecution timeMemory
1025648ZicrusFeast (NOI19_feast)C++17
53 / 100
77 ms51604 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } if (n <= 2000 && k <= 2000) { vector<vector<ll>> dp(n, vector<ll>(k+1)); vector<vector<ll>> dpSeg(n, vector<ll>(k+1)); for (int j = 1; j <= k; j++) { dpSeg[0][j] = max(0ll, a[0]); } for (int i = 1; i < n; i++) { for (int j = 1; j <= k; j++) { dp[i][j] = max(dp[i-1][j], dpSeg[i-1][j]); dpSeg[i][j] = max(dp[i-1][j-1], dpSeg[i-1][j]) + a[i]; } } cout << max(dp.back().back(), dpSeg.back().back()); return 0; } ll sum = 0; ll pre = 0, post = 0; bool neg = false; for (auto &e : a) { if (neg) post += e; if (e < 0) { neg = true; pre = sum; } sum += e; } if (!neg) { cout << sum; return 0; } if (k == 1) { cout << max({pre, post, sum}); } else { cout << (pre + post); } }
#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...