Submission #876266

#TimeUsernameProblemLanguageResultExecution timeMemory
876266Beerus13Split the sequence (APIO14_sequence)C++14
0 / 100
2070 ms130964 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define bit(mask, i) ((mask >> i) & 1) const int ar = 1e5 + 5; int n, k; ll sum[ar], pos[205][ar], dp[205][ar], Max[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 = i; j <= n; ++j) { for(int h = i - 1; 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'; while(ind) { cout << ind << ' '; ind = pos[k][ind]; --k; } }
#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...