제출 #738489

#제출 시각아이디문제언어결과실행 시간메모리
738489MODDIK개의 묶음 (IZhO14_blocks)C++14
0 / 100
1 ms316 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n, k;
vl arr;
pll dp[100100][101];
int main(){
	cin>>n>>k;
	arr.resize(n);
	for(int i = 0; i < n; i++)	cin>>arr[i];

	dp[0][1] = mp(0, arr[0]);
	dp[0][2] = mp(arr[0], 0);
	for(int i = 1; i < n; i++){
		for(int block = 1; block <= k; block++){
			dp[i][block] = mp(dp[i-1][block].first, max(dp[i-1][block].second, arr[i]));
			if(block -1 >= 1)
			{
				if(dp[i][block].first > dp[i-1][block-1].first + dp[i-1][block-1].second){
					dp[i][block] = mp(dp[i-1][block-1].first + dp[i-1][block-1].second, arr[i]);
				}
			}
		}
	}
	cout<<dp[n-1][k].first+dp[n-1][k].second<<endl;
	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...