Submission #855460

#TimeUsernameProblemLanguageResultExecution timeMemory
855460vjudge1Split the sequence (APIO14_sequence)C++17
50 / 100
2039 ms33292 KiB
#include <bits/stdc++.h> #define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define all(x) (x).begin(), (x).end() #define pb push_back #define sz(x) (int)x.size() #define F first #define S second #define int long long const int maxn = 1e4+7; const int inf = 1e18; const int mod = 1e9+7; using namespace std; int n, k; int a[maxn]; int pref[maxn]; int dp[210][maxn]; int p[210][maxn]; void solve(){ cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } for(int i = 1; i <= n; i++) dp[0][i] = -inf; for(int i = 1; i <= k + 1; i++){ for(int j = 1; j <= n; j++){ int res = -inf; for(int pos = 0; pos < j; pos++){ if(dp[i - 1][pos] + (pref[j] - pref[pos]) * (pref[pos]) >= res){ res = dp[i - 1][pos] + (pref[j] - pref[pos]) * (pref[pos]); p[i][j] = pos; } } dp[i][j] = res; } } cout << dp[k + 1][n] << '\n'; int x = k + 1, y = n; while(x > 1){ y = p[x][y]; x--; if(y != 0){ cout << y << ' '; } } } signed main(){ speed int test = 1; // cin >> test; while(test--){ 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...