제출 #25163

#제출 시각아이디문제언어결과실행 시간메모리
25163RezwanArefin01수열 (APIO14_sequence)C++14
0 / 100
0 ms1844 KiB
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10, K = 202; 
ll dp[K][N], par[K][N], arr[N], p[N];

int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
	freopen("in", "r", stdin);
#endif 	
	int n, kk; cin>>n>>kk;
	for(int i=1; i <= n; i++) {
		cin>>arr[i]; 
		p[i] = p[i-1] + arr[i];
	}

	for(int i=1; i <= n; i++) dp[1][i] = p[i] * (p[n] - p[i]);

	for(int k=2; k <= kk+1; k++) {
		for(int i=1; i<=n; i++) {
			par[k][i] = -1;
			for(int j=0; j<i; j++) {
				ll op = (dp[k-1][j] + (p[i] - p[j]) * p[j]);
				if(op > dp[k][i]) {
					dp[k][i] = op;
					par[k][i] = j;
				} 
			}
		}
	}  
	cout<<dp[kk][n]<<endl; 
	int x = par[kk][n];
	while(x != -1) {
		cout<<x<<" ";
		x = par[kk][x];
	}

}
#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...