답안 #388370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388370 2021-04-11T06:31:56 Z warner1129 Stove (JOI18_stove) C++17
0 / 100
64 ms 98372 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 5005;

int arr[maxn];
int dp[maxn][maxn], pre[maxn][maxn];

void solve() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> arr[i];
	m = min(m, n);
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	pre[0][0] = -arr[1];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i; j++) {
			dp[i][j] = arr[i] + pre[i-1][j-1];
			pre[i][j] = min(pre[i-1][j], dp[i][j] - arr[i+1] + 1);
		}
	cout << dp[n][m] << '\n';
}

signed main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 98372 KB Output is correct
2 Incorrect 42 ms 98336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 98372 KB Output is correct
2 Incorrect 42 ms 98336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 98372 KB Output is correct
2 Incorrect 42 ms 98336 KB Output isn't correct
3 Halted 0 ms 0 KB -