This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int N, K;
cin >> N >> K;
vector<ll> a(N);
for (int i = 0; i < N; i++)
cin >> a[i];
// Maximize satisfaction with 1, then 2, then ... segments
vector<vector<ll>> dp(K+1, vector<ll>(N));
vector<vector<ll>> mx(K+1, vector<ll>(N));
ll res = 0;
for (int k = 1; k <= K; k++)
{
for (int i = 0; i < N; i++)
{
dp[k][i] = max(0ll, a[i]);
if (i)
dp[k][i] = max({dp[k][i], dp[k][i-1] + a[i], mx[k-1][i-1] + a[i]});
mx[k][i] = dp[k][i];
if (i)
mx[k][i] = max(mx[k][i-1], dp[k][i]);
res = max(res, mx[k][i]);
}
}
cout << res << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |