# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
731249 | Baytoro | Split the sequence (APIO14_sequence) | C++17 | 138 ms | 6996 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;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl "\n"
#define ll long long
#define int long long
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=1e3+5;
int n,m;
int dp[N][205],par[N][205],a[N],pref[N];
void solve(){
int n,k;cin>>n>>k;
dp[0][0]=0;
for(int i=1;i<=n;i++){
cin>>a[i];
pref[i]=a[i]+pref[i-1];
}
for(int j=1;j<=k+1;j++){
for(int i=1;i<=n;i++){
dp[i][j]=-INF;
par[i][j]=1;
for(int last=i;last>=1;last--){
if(dp[i][j]<dp[last-1][j-1]+(pref[i]-pref[last-1])*(pref[n]-pref[i])){
dp[i][j]=dp[last-1][j-1]+(pref[i]-pref[last-1])*(pref[n]-pref[i]);
par[i][j]=last-1;
}
}
if(par[i][j]==0) par[i][j]=1;
}
}
cout<<dp[n][k+1]<<endl;
vector<int> ans;
int cur=n;
for(int i=k;i>0;i--){
cur=par[cur][i+1];
ans.pb(cur);
}
reverse(all(ans));
for(auto it: ans) cout<<it<<' ';
}
main(){
//fopn("balancing");
ios;
int T=1;
//cin>>T;
for(int i=1;i<=T;i++){
//cout<<"Case #"<<i<<": ";
solve();
}
}
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... |