제출 #761862

#제출 시각아이디문제언어결과실행 시간메모리
761862yellowtoad수열 (APIO14_sequence)C++17
0 / 100
15 ms6552 KiB
#include <iostream>
using namespace std;

long long n, k, a[100010], dp[210][100010], maxx[210][100010], ps[100010], ans;

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		ps[i] = ps[i-1]+a[i];
	}
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j < n; j++) {
			dp[i][j] = dp[i-1][maxx[i-1][j-1]]+(ps[j]-ps[maxx[i-1][j-1]])*(ps[n]-ps[j]);
			if (dp[i][maxx[i][j-1]]+(ps[j+1]-ps[maxx[i][j-1]])*(ps[n]-ps[j+1]) >= dp[i][j]+a[j+1]*(ps[n]-ps[j+1])) {
				maxx[i][j] = maxx[i][j-1];
			} else maxx[i][j] = j;
			//cout << dp[i][j] << " ";
		} //cout << endl;
	}
	for (int i = 1; i < n; i++) ans = max(ans,dp[k][i]);
	cout << ans << endl;
	for (int i = 1; i < n; i++) {
		if (ans == dp[k][i]) {
			int tmp = i;
			for (int j = k; j >= 1; j--) {
				if (j != k) cout << " ";
				cout << tmp;
				tmp = maxx[j-1][tmp];
			} cout << endl;
			break;
		}
	}
}
#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...