# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1032699 | vannnnnnnn | Split the sequence (APIO14_sequence) | C++14 | 2029 ms | 6784 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>
#define fi first
#define se second
#define ll long long
using namespace std;
ll n, k, pre[10005], a[10005];
pair<ll, ll>dp[205][10005];
int main()
{
ll n, k;
scanf("%lld %lld", &n, &k);
for(int i=1; i<=n; i++)
{
scanf("%d", &a[i]);
pre[i]=pre[i-1]+a[i];
}
for(int i=1; i<=k; i++)
{
for(int l=0; l<n-1; l++)
{
for(int r=l+1; r<n; r++)
{
if(dp[i][r].fi<dp[i-1][l].fi+(pre[r]-pre[l])*(pre[n]-pre[r]))
{
dp[i][r].fi=dp[i-1][l].fi+(pre[r]-pre[l])*(pre[n]-pre[r]);
dp[i][r].se=l;
// printf("%lld %lld %d %d %d\n", dp[i][r].fi, dp[i][r].se, i, r, l);
}
}
}
}
ll ans=0, idx;
for(int i=1; i<=n; i++)
{
if(ans<dp[k][i].fi)
{
ans=dp[k][i].fi;
idx=i;
}
}
printf("%lld\n", ans);
vector<int>res;
while(idx!=0)
{
res.push_back(idx);
idx=dp[k][idx].se;
k--;
}
reverse(res.begin(), res.end());
for(auto x:res)printf("%d ", x);
printf("\n");
}
/*
7 3
4 1 3 4 0 2 3
*/
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... |