Submission #876270

#TimeUsernameProblemLanguageResultExecution timeMemory
876270Beerus13Split the sequence (APIO14_sequence)C++14
39 / 100
2087 ms131072 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int ar = 1e5 + 5; int n, k; ll sum[ar], pos[205][ar], dp[205][ar]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 1; i <= n; ++i) { int x; cin >> x; sum[i] = sum[i - 1] + x; } for(int i = 1; i <= k; ++i) { for(int j = 1; j <= n; ++j) { for(int h = 0; h < j; ++h) { dp[i][j] = max(dp[i][j], dp[i - 1][h] + (sum[j] - sum[h]) * (sum[n] - sum[j])); if(dp[i][j] == dp[i - 1][h] + (sum[j] - sum[h]) * (sum[n] - sum[j])) pos[i][j] = h; } } } ll mx = -1, ind = 0; for(int i = k; i <= n; ++i) { if(dp[k][i] > mx) mx = dp[k][i], ind = i; } cout << mx << '\n'; for(int i = k; i; --i) { cout << ind << ' '; ind = pos[i][ind]; } }
#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...