Submission #647067

#TimeUsernameProblemLanguageResultExecution timeMemory
647067googleSplit the sequence (APIO14_sequence)C++17
50 / 100
2076 ms32572 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int szn = 10001,szk=201; ll dp[szn][szk],arr[szn],pre[szn],n,k; int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> k; for (int i = 0;i<n;i++) { cin >> arr[i]; pre[i] = arr[i]; if (i) pre[i] += pre[i-1]; } memset(dp,0,sizeof(dp)); for (int c = 1;c<=k;c++){ for (int i = c;i<n;i++){ for (int j = 0;j<i;j++){ if (dp[i][c] < dp[j][c-1]+(pre[j]*(pre[i]-pre[j]))){ dp[i][c] = dp[j][c-1]+(pre[j]*(pre[i]-pre[j])); } } } } cout << dp[n-1][k] << '\n'; int t = n-1, c = k; vector<ll> ans; for (int i = n-2;;i--){ if (dp[t][c] == dp[i][c-1]+pre[i]*(pre[t]-pre[i])){ ans.push_back(i+1); t = i; c--; } if (!c) break; } for (auto a:ans) cout << a << ' '; 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...