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;
const int maxn=1e5+10;
int n;
int k;
int x[maxn];
int sum[maxn];
vector<int>ans;
int f(int idx,int kol,vector<int>v)
{
if(kol==0)
{
ans=v;
return sum[n-1]-sum[idx];
}
int rez=0;
for(int i=idx+1;i<n-1;i++)
{
vector<int>pom;
pom=v;
pom.push_back(i);
if(idx==-1)
{
int koj=kol-1;
if(koj>=0)
rez=max(rez, f(i,koj,pom)*sum[i]);
}
else
{
int koj=kol-1;
if(koj>=0)
rez=max(rez, f(i,koj,pom)*(sum[i]-sum[idx]));
}
}
return rez;
}
int main()
{
cin>>n>>k;
for(int i=0;i<n;i++)
{
cin>>x[i];
if(i==0)
{
sum[i]=x[i];
}
else
{
sum[i]=sum[i-1]+x[i];
}
}
vector<int>v;
cout<<f(-1,k,v)<<endl;
for(auto p:ans)
{
cout<<p<<" ";
}
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... |