Submission #388372

# Submission time Handle Problem Language Result Execution time Memory
388372 2021-04-11T06:44:42 Z warner1129 Stove (JOI18_stove) C++17
50 / 100
303 ms 262144 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));
	memset(pre, 0x3f, sizeof(pre));
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) pre[i][0] = -arr[1] + 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;
}
# Verdict Execution time Memory Grader output
1 Correct 80 ms 196292 KB Output is correct
2 Correct 84 ms 196320 KB Output is correct
3 Correct 81 ms 196312 KB Output is correct
4 Correct 81 ms 196284 KB Output is correct
5 Correct 82 ms 196388 KB Output is correct
6 Correct 81 ms 196264 KB Output is correct
7 Correct 81 ms 196292 KB Output is correct
8 Correct 81 ms 196368 KB Output is correct
9 Correct 81 ms 196348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 196292 KB Output is correct
2 Correct 84 ms 196320 KB Output is correct
3 Correct 81 ms 196312 KB Output is correct
4 Correct 81 ms 196284 KB Output is correct
5 Correct 82 ms 196388 KB Output is correct
6 Correct 81 ms 196264 KB Output is correct
7 Correct 81 ms 196292 KB Output is correct
8 Correct 81 ms 196368 KB Output is correct
9 Correct 81 ms 196348 KB Output is correct
10 Correct 90 ms 196408 KB Output is correct
11 Correct 90 ms 196424 KB Output is correct
12 Correct 91 ms 196416 KB Output is correct
13 Correct 89 ms 196384 KB Output is correct
14 Correct 89 ms 196404 KB Output is correct
15 Correct 91 ms 196376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 196292 KB Output is correct
2 Correct 84 ms 196320 KB Output is correct
3 Correct 81 ms 196312 KB Output is correct
4 Correct 81 ms 196284 KB Output is correct
5 Correct 82 ms 196388 KB Output is correct
6 Correct 81 ms 196264 KB Output is correct
7 Correct 81 ms 196292 KB Output is correct
8 Correct 81 ms 196368 KB Output is correct
9 Correct 81 ms 196348 KB Output is correct
10 Correct 90 ms 196408 KB Output is correct
11 Correct 90 ms 196424 KB Output is correct
12 Correct 91 ms 196416 KB Output is correct
13 Correct 89 ms 196384 KB Output is correct
14 Correct 89 ms 196404 KB Output is correct
15 Correct 91 ms 196376 KB Output is correct
16 Runtime error 303 ms 262144 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -