제출 #973003

#제출 시각아이디문제언어결과실행 시간메모리
973003oviyan_gandhi수열 (APIO14_sequence)C++17
50 / 100
2066 ms81668 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define N 100001 #define K 201 int ps[N]; pair<int, int> dp[N][K]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++){ cin >> ps[i]; ps[i] += ps[i-1]; } for (int l = 1; l <= k; l++) for (int i = 1; i <= n; i++) for (int j = i-1; j > 0; j--) dp[i][l] = max(dp[i][l], {dp[j][l-1].first + ps[j]*(ps[i] - ps[j]), j}); cout << dp[n][k].first << '\n'; int curr = n; for (int i = k; i > 0; i--){ cout << dp[curr][i].second << ' '; curr = dp[curr][i].second; } cout << '\n'; 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...