이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <bits/stdc++.h>
 
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
 
using namespace std;
ll dp[1001][201];
ll prevs[1001][201];
int main(){
	
	ll n,k;
	cin >> n >> k;
	vector<ll> arr(n);
	vector<ll> pref(n);
	FOR(i,0,n) cin >> arr[i];
	pref[0] = arr[0];
	FOR(i,1,n) pref[i] = pref[i-1]+arr[i];
	FOR(i,0,1001)FOR(j,0,201) dp[i][j] = 0;
	deque<vector<ll>> sus;
	FOR(i,1,n+1){
		FOR(j,1,k+1){
			FOR(m,0, i){
				ll temp = dp[m][j-1] + (pref[n-1] - pref[i-1]) * (pref[i-1]-pref[m]+arr[m]);
				if (dp[i][j] < temp){
					dp[i][j] = temp;
					prevs[i][j] = m;
				}
			}
		}
	}
	ll maxi = -1;
	ll pos = -1;
	FOR(i,0,n) if (dp[i][k] > maxi) maxi = dp[i][k], pos = i;
	cout << dp[pos][k] << endl;
	while (pos != 0){
		ll sus = prevs[pos][k];
		k--;
		cout << pos << " ";
		pos  = sus;
		
	}
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |