# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1046614 | vanea | Split the sequence (APIO14_sequence) | C++14 | 16 ms | 131072 KiB |
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;
using ll = long long;
int main()
{
freopen("sequence.in", "r", stdin);
freopen("sequence.out", "w", stdout);
int n, k;
cin >> n >> k;
vector<ll> v(n+1);
for(int i = 1; i <= n; i++) {
cin >> v[i];
}
vector<ll> pref(n+1), suf(n+2);
for(int i = 1; i <= n; i++) {
pref[i] = pref[i-1]+v[i];
}
for(int i = n; i>=1; i--) {
suf[i] = suf[i+1]+v[i];
}
vector<vector<array<ll, 2>>> dp(n+1, vector<array<ll, 2>>(k+1));
ll ans = 0;
for(int i = 1; i < n; i++) {
for(int j = 1; j <= min(k, i); j++) {
array<ll, 2> f = dp[i-1][j]; f[1]+=v[i];
array<ll, 2> s = dp[i-1][j-1];
s[1] += v[i]; s[0] += (s[1] * suf[i+1]); s[1] = 0;
dp[i][j] = max(f, s);
ans = max(ans, dp[i][j][0]);
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | 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... |