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<iostream>
#include<deque>
#include<fstream>
using namespace std;
ifstream fin("./sequence/53");
long long d[100007][205],n,k,a[200000],A[200000],opt[100007][205];
long long i,j,cur;
deque<pair<long long,long long> > q;
int main()
{
cin>>n>>k;
for(i=1;i<=n;i++)
{
cin>>a[i];
A[i]=A[i-1]+a[i];
}
for(j=1;j<=k;j++)
{
for(i=j+1;i<=n;i++)
{
for(int cur=max(opt[i][j-1],max(opt[i-1][j],j));cur<=i;cur++)
{
if((A[i]-A[cur])*A[cur]+d[cur][j-1]>=d[i][j])
{
d[i][j] = (A[i]-A[cur])*A[cur]+d[cur][j-1];
opt[i][j]=cur;
}
}
}
}
cout<<d[n][k]<<endl;
long long l=n,r=k;
for(i=n-1;i>=1;i--)
{
if((A[l]-A[i])*A[i]+d[i][r-1]==d[l][r])
{
cout<<i<<" ";
r--;
if(r==0)
break;
l=i;
}
}
return 0;
}
/*
7 3
4 1 3 4 0 2 3*/
# | 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... |