Submission #381776

#TimeUsernameProblemLanguageResultExecution timeMemory
381776jlallas384Split the sequence (APIO14_sequence)C++17
0 / 100
181 ms6380 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; ll dp[1005][205]; ll pref[1005]; int par[1005][205]; int main(){ int n,k; cin >> n >> k; vector<int> a(n); for(auto &x: a){ cin >> x; } for(int i = 0; i < n; i++){ pref[i+1] = pref[i] + a[i]; } ll sm = accumulate(a.begin(),a.end(),0); int mx = 0,id = 0; for(int i = 1; i <= n; i++){ sm -= a[i-1]; for(int j = 1; j <= k; j++){ for(int l = 0; l < i; l++){ ll res = dp[l][j-1] + (pref[i] - pref[l]) * sm; if(res > dp[i][j]){ dp[i][j] = res; par[i][j] = l; } } } if(dp[i][k] > mx){ mx = dp[i][k]; id = i; } } cout << dp[id][k] << "\n"; vector<int> res; while(id != 0){ res.push_back(id); id = par[id][k--]; } reverse(res.begin(), res.end()); for(int x: res){ cout << x << " "; } }
#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...