Submission #1053949

#TimeUsernameProblemLanguageResultExecution timeMemory
1053949TAhmed33Split the sequence (APIO14_sequence)C++98
0 / 100
2021 ms131072 KiB
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; int dp[100001][202], a[100001], n, m; int 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) -> int { 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--) { int 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 <int> 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...