# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
112114 | _demon_ | Split the sequence (APIO14_sequence) | C++14 | 152 ms | 3676 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>
using namespace std;
long long n,k;
long long a[1009];
long long dp[1009][209];
long long p[1009][209];
long long sum[1009];
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i];
for(int i=1;i<=n;i++){
long long crnt=0;
for(long long j=i;j>=1;j--){
crnt+=a[j];
for(int K=1;K<=k+1;K++){
if(dp[i][K]<dp[j-1][K-1]+crnt*(sum[n]-sum[i])){
dp[i][K]=dp[j-1][K-1]+crnt*(sum[n]-sum[i]);
p[i][K]=j-1;
}
if(dp[i][K]==dp[j-1][K-1]+crnt*(sum[n]-sum[i])){
dp[i][K]=dp[j-1][K-1]+crnt*(sum[n]-sum[i]);
p[i][K]=max(p[i][K],j-1);
}
}
}
}
cout<<dp[n][k+1]<<endl;
vector<int>v;
int ii=n;int kk=k+1;
while(kk>1){
v.push_back(p[ii][kk]);
ii=p[ii][kk];
kk--;
}
reverse(v.begin(),v.end());
for(int i=0;i<v.size();i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
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... |