제출 #1046612

#제출 시각아이디문제언어결과실행 시간메모리
1046612vanea수열 (APIO14_sequence)C++14
0 / 100
15 ms12940 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<ll> v(n+1); for(int i = 1; i <= n; i++) { cin >> v[i]; } vector<ll> pref(n+1), suf(n+2); for(int i = 1; i <= n; i++) { pref[i] = pref[i-1]+v[i]; } for(int i = n; i>=1; i--) { suf[i] = suf[i+1]+v[i]; } vector<vector<array<ll, 2>>> dp(n+1, vector<array<ll, 2>>(k+1)); ll ans = 0; for(int i = 1; i < n; i++) { for(int j = 1; j <= min(k, i); j++) { array<ll, 2> f = dp[i-1][j]; f[1]+=v[i]; array<ll, 2> s = dp[i-1][j-1]; s[1] += v[i]; s[0] += (s[1] * suf[i+1]); s[1] = 0; dp[i][j] = max(f, s); ans = max(ans, dp[i][j][0]); } } cout << ans; return 0; }
#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...