Submission #130109

#TimeUsernameProblemLanguageResultExecution timeMemory
130109mlyean00Split the sequence (APIO14_sequence)C++14
50 / 100
2060 ms31992 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<ll> pref(n + 1, 0); partial_sum(a.begin(), a.end(), pref.begin() + 1); ll dp[k + 1][n], parent[k + 1][n]; memset(dp, 0xff, sizeof(dp)); memset(parent, 0xff, sizeof(dp)); for (int j = 0; j < n; ++j) { dp[0][j] = 0; } for (int i = 1; i <= k; ++i) { for (int j = 0; j < n; ++j) { for (int h = 0; h < j; ++h) { if (dp[i - 1][h] == -1) continue; ll t = dp[i - 1][h] + (pref[h + 1] - pref[0]) * (pref[j + 1] - pref[h + 1]); if (t >= dp[i][j]) { dp[i][j] = t; parent[i][j] = h; } } } } ll max_pts = -1; int u = 0; for (int j = 0; j < n; ++j) { if (dp[k][j] > max_pts) { max_pts = dp[k][j]; u = j; } } cout << max_pts << endl; for (int i = k; i > 0; --i) { u = parent[i][u]; cout << (u + 1) << ' '; } cout << endl; 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...