Submission #724981

#TimeUsernameProblemLanguageResultExecution timeMemory
724981AndrijaMSplit the sequence (APIO14_sequence)C++14
0 / 100
2071 ms980 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...