#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> bool maximize(T &a, const T &b){ return (a < b ? a = b, 1 : 0); }
template<class T> bool minimize(T &a, const T &b){ return (a > b ? a = b, 1 : 0); }
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define all(x) x.begin(), x.end()
#define TASK "nonsense"
/// end of template ///
const int N = 1e5 + 5;
const int K = 200 + 5;
int n,k,a[N],p[N];
namespace sub123
{
const int N = 200+1;
bool check()
{
return (n<N);
}
ll dp[N][N][N];
ii trace[N][N][N];
void work(int tri, int i, int j)
{
if(i==j || tri==0) return;
int tri1=trace[tri][i][j].fi;
int pos=trace[tri][i][j].se;
cout<<pos<<' ';
work(tri1,i,pos);
work(tri-1-tri1,pos+1,j);
}
void solve()
{
for(int tri=1;tri<=k;++tri) for(int i=1;i<=n;++i) for(int j=i;j<=n;++j)
{
dp[tri][i][j]=-1;
// bool dbg=(tri==3 && i==1 && j==7);
for(int tri1=0;tri1<=tri-1;++tri1)
{
int tri2=tri-1-tri1;
// cout<<tri<<' '<<tri1<<' '<<tri2<<'\n';
for(int pos=i;pos<j;++pos)
{
// if(dbg) cout<<tri<<' '<<tri1<<' '<<tri2<<' '<<pos<<' '<<dp[tri1][i][pos]<<' '<<dp[tri2][pos+1][j]<<' '<<(p[j]-p[pos])*1LL*(p[pos]-p[i-1])<<'\n';
if(maximize(dp[tri][i][j],dp[tri1][i][pos]+dp[tri2][pos+1][j]+(p[j]-p[pos])*1LL*(p[pos]-p[i-1]))) trace[tri][i][j]=make_pair(tri1,pos);
}
}
// cout<<tri<<' '<<i<<' '<<j<<' '<<dp[tri][i][j]<<'\n';
}
cout<<dp[k][1][n]<<'\n';
work(k,1,n);
}
}
void solve()
{
cin>>n>>k;
for(int i=1;i<=n;++i) cin>>a[i],p[i]=p[i-1]+a[i];
if(sub123::check()) return void(sub123::solve());
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
int testcase=1;
// cin>>testcase;
while (testcase--)
solve();
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... |