Submission #1053948

#TimeUsernameProblemLanguageResultExecution timeMemory
1053948TAhmed33Split the sequence (APIO14_sequence)C++98
0 / 100
20 ms131072 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 1e15; ll dp[100001][202], a[100001], n, m; ll par[100001][202]; void solve () { cin >> n >> m; m++; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; } memset(par, -1, sizeof(par)); for (int i = 1; i <= n; i++) { dp[i][0] = -inf; } auto f = [&] (int l, int r) -> ll { return (a[r] - a[l - 1]) * a[l - 1]; }; for (int j = 1; j <= m; j++) { for (int i = 0; i < j; i++) { dp[i][j] = -inf; } for (int i = j; i <= n; i++) { dp[i][j] = -inf; for (int k = i - 1; k >= 0; k--) { ll x = dp[k][j - 1] + f(k + 1, i); if (x > dp[i][j]) { dp[i][j] = x; par[i][j] = k; } } } } cout << dp[n][m] << '\n'; vector <ll> u; int t = n, c = m; while (true) { if (par[t][c] == -1) { break; } u.push_back(par[t][c]); t = par[t][c]; c--; } u.pop_back(); reverse(u.begin(), u.end()); for (auto i : u) cout << i << " "; cout << '\n'; } signed main () { ios::sync_with_stdio(0); cin.tie(0); int tc = 1; //cin >> tc; while (tc--) solve(); }
#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...