Submission #1110648

#TimeUsernameProblemLanguageResultExecution timeMemory
1110648simona1230Split the sequence (APIO14_sequence)C++17
11 / 100
2056 ms6728 KiB
#include <bits/stdc++.h> using namespace std; const int maxn=301; long long n,k; long long a[200001]; long long dp[maxn][maxn]; long long p[maxn]; void read() { cin>>n>>k; for(long long i=1;i<=n;i++) { cin>>a[i]; p[i]=p[i-1]+a[i]; } } long long idx[maxn][maxn]; vector<long long> ans; void rec(long long i,long long c) { if(c==0)return; ans.push_back(idx[i][c]); rec(idx[i][c],c-1); } void solve() { for(long long i=1;i<=n;i++) { for(long long j=1;j<=n;j++) { for(long long l=0;l<i;l++) { long long curr=dp[l][j-1]+(p[i]-p[l])*p[l]; if(dp[i][j]<curr) { dp[i][j]=curr; idx[i][j]=l; } } } } cout<<dp[n][k]<<endl; rec(n,k); sort(ans.begin(),ans.end()); for(long long i=0;i<k;i++) cout<<ans[i]<<" "; cout<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); read(); solve(); return 0; } /* 7 3 4 1 3 4 0 2 3 */
#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...