제출 #669744

#제출 시각아이디문제언어결과실행 시간메모리
669744Dan4LifeSplit the sequence (APIO14_sequence)C++17
50 / 100
2077 ms31976 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(a) a.begin(),a.end()
#define mp make_pair
#define fi first
#define se second
 
const int maxn = (int)1e4+10;
int n, K, a[maxn], pre[maxn];
int dp[maxn][201], p[maxn][201];
vector<int> v;
inline int sum(int i, int j) { if(i>j) return 0; return pre[j+1]-pre[i];}
 
void recur(int i, int k){ if(k) v.pb(i), recur(p[i][k],k-1); }
 
int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> K; int ans = -(int)1e18, st=-1;
    for(int i = 0; i < n; i++) cin >> a[i], pre[i+1]=pre[i]+a[i];
    for(int i = 0; i <= n; i++)
        for(int k = 0; k <= K; k++)
            dp[i][k]=(k==0?0:-(int)1e18);
    for(int k = 1; k <= K; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 0; j < i; j++){
                int tot = dp[j][k-1]+(pre[i]-pre[j])*(pre[n]-pre[i]);
                if(dp[i][k] < tot) dp[i][k]=tot, p[i][k]=j;
            }
        }
    }
    for(int i = 1; i <= n; i++) if(ans<dp[i][K]) ans=dp[i][K], st=i;
    cout << ans << "\n"; recur(st,K);
    sort(all(v)); for(auto u : v) cout << u << " ";
}
#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...