#include <bits/stdc++.h>
using namespace std;
const int H = 200, N = 300;
int dp[1 + N][1 + H][1 + H];
int a[1 + N];
void upd (int &a, int b) {
if (a > b)
a = b;
}
int main () {
ios::sync_with_stdio (false);
cin.tie (0); cout.tie (0);
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= H; j++)
for (int k = 0; k <= H; k++)
dp[i][j][k] = (1 << 30);
for (int i = 1; i <= n; i++) {
if (i == 1)
dp[i][0][a[i]] = 0;
/// push dp through the level
for (int j = H; j >= 0; j--)
for (int k = H; k >= 0; k--) {
if (k)
upd (dp[i][j][k - 1], dp[i][j][k] + 3);
if (j && k)
upd (dp[i][j - 1][k - 1], dp[i][j][k] + 5);
}
/// push dp to the next level
if (i < n)
for (int j = H; j >= 0; j--)
for (int k = H; k >= 0; k--)
if (a[i + 1] >= j && k >= j)
upd (dp[i + 1][k - j][a[i + 1] - j], dp[i][j][k] + j * 7);
}
cout << dp[n][0][0] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
876 KB |
Output is correct |
3 |
Correct |
2 ms |
1260 KB |
Output is correct |
4 |
Correct |
15 ms |
11628 KB |
Output is correct |
5 |
Correct |
2 ms |
1388 KB |
Output is correct |
6 |
Correct |
3 ms |
2028 KB |
Output is correct |
7 |
Correct |
3 ms |
1900 KB |
Output is correct |
8 |
Correct |
2 ms |
1644 KB |
Output is correct |
9 |
Correct |
4 ms |
2540 KB |
Output is correct |
10 |
Correct |
7 ms |
4332 KB |
Output is correct |
11 |
Correct |
38 ms |
22764 KB |
Output is correct |
12 |
Correct |
9 ms |
5356 KB |
Output is correct |
13 |
Correct |
45 ms |
26860 KB |
Output is correct |
14 |
Correct |
56 ms |
31980 KB |
Output is correct |
15 |
Correct |
86 ms |
43904 KB |
Output is correct |
16 |
Correct |
77 ms |
39404 KB |
Output is correct |
17 |
Correct |
97 ms |
47980 KB |
Output is correct |
18 |
Correct |
98 ms |
47680 KB |
Output is correct |
19 |
Correct |
91 ms |
45932 KB |
Output is correct |
20 |
Correct |
95 ms |
48108 KB |
Output is correct |