Submission #927459

#TimeUsernameProblemLanguageResultExecution timeMemory
927459AlphaMale06Split the sequence (APIO14_sequence)C++17
50 / 100
2089 ms130908 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back int dp[2][205][100010]; signed main() { int n, k; cin >> n >> k; int a[n]; int pref[n]; int prev=0; for(int i=0; i< n; i++){ cin >> a[i]; pref[i]=prev+a[i]; prev=pref[i]; } for(int j=1; j<=k; j++){ for(int i=0; i<n; i++){ for(int l=i; l>=j-1; l--){ int val = dp[0][j-1][l]+pref[l]*(pref[i]-pref[l]); if(val>=dp[0][j][i]){ dp[0][j][i]=val; dp[1][j][i]=l; } } } } cout << dp[0][k][n-1] << '\n'; vector<int> con; prev=n-1; for(int i=k; i>0; i--){ con.pb(dp[1][i][prev]); prev=con.back(); } reverse(con.begin(), con.end()); for(int e : con)cout << e+1 << " "; }
#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...