답안 #53354

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53354 2018-06-29T15:04:26 Z MatheusLealV K개의 묶음 (IZhO14_blocks) C++17
0 / 100
12 ms 9564 KB
#include <bits/stdc++.h>
#define N 100010
#define K 110
using namespace std;

int n, k, v[N], pref[N], dp[N][K], best[N][K];

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n>>k;

	for(int i = 1; i <= n; i++) cin>>v[i];

	for(int i = 1; i <= n; i++)
	{
		dp[i][1] = max(dp[i - 1][1], v[i]);

		best[i][1] = dp[i][1];

		pref[i] = pref[i - 1] + v[i];
	}

	for(int q = 2; q <= k; q++)
	{
		for(int i = 1; i <= n; i++)
		{
			if(i < q) continue;

			if(i == q)
			{
				dp[i][q] = pref[i];

				best[i][q] = v[i];

				continue;
			}

			int A = dp[i - 1][q] + max(v[i] - best[i - 1][q], 0);

			int B = dp[i - 1][q - 1] + v[i];

			if(A <= B) best[i][q] = max(v[i], best[i - 1][q]);

			else best[i][q] = v[i];

			dp[i][q] = min(A, B);
		}
	}

	cout<<dp[n][k]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 532 KB Output is correct
3 Correct 2 ms 532 KB Output is correct
4 Correct 3 ms 532 KB Output is correct
5 Correct 3 ms 532 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
7 Correct 3 ms 532 KB Output is correct
8 Correct 2 ms 532 KB Output is correct
9 Correct 2 ms 580 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Incorrect 2 ms 720 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 720 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 880 KB Output is correct
5 Correct 2 ms 880 KB Output is correct
6 Correct 3 ms 880 KB Output is correct
7 Correct 2 ms 880 KB Output is correct
8 Correct 3 ms 880 KB Output is correct
9 Correct 2 ms 908 KB Output is correct
10 Correct 2 ms 908 KB Output is correct
11 Incorrect 2 ms 932 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 9564 KB Output isn't correct
2 Halted 0 ms 0 KB -