#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;
}
if (k == 1) {
cout << max({pre, post, sum});
}
else {
cout << (pre + post);
}
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:41:9: error: return-statement with no value, in function returning 'int' [-fpermissive]
41 | return;
| ^~~~~~