제출 #876273

#제출 시각아이디문제언어결과실행 시간메모리
876273Beerus13수열 (APIO14_sequence)C++14
50 / 100
2075 ms130980 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 = 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'; 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...