답안 #28387

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28387 2017-07-16T05:09:21 Z laaS(#1111, fpdjsns) 포도주 시음 (FXCUP2_wine) C++14
0 / 1
0 ms 9052 KB
#include<iostream>
#include<algorithm>

using namespace std;

long long int d[2][300000];
long long int arr[300000];
int main()
{
	int n, k;
	cin >> n >> k;
	bool ind = false;
	for (int i = 0; i < n; i++)
	{
		cin >> d[ind][i];
		arr[i] = d[ind][i];
	}
	long long int temp = 0;
	for (int i = 1; i < k; i++)
	{
		ind = !ind;

		for (int j = i; j < n; j++)
		{
			d[ind][j] = 0;
			for (int k = i - 1; k < j; k++)
			{
				temp = d[!ind][k];
				if (arr[k] < arr[j])
					temp += arr[j] - arr[k];
				d[ind][j] = max(d[ind][j], temp);
			}
		}
	}
	temp = d[ind][k - 1];
	for (int i = k; i < n; i++)
		temp = max(temp, d[ind][i]);
	cout << temp;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9052 KB Output is correct
2 Correct 0 ms 9052 KB Output is correct
3 Incorrect 0 ms 9052 KB Output isn't correct
4 Halted 0 ms 0 KB -