#include <stdio.h>
#include <algorithm>
#define N_MAX 300
#define H_MAX 200
using namespace std;
int N, H[N_MAX+3], D[2][H_MAX+1][H_MAX+1];
int main(void) {
int i, j, k, now, prev;
scanf("%d",&N);
for(i=1 ; i<=N ; i++)
scanf("%d",&H[i]);
for(i=0 ; i<=H[1] ; i++)
for(j=0 ; j<=H[2] ; j++)
D[0][i][j]=5*min(i,j)+3*(max(i,j)-min(i,j));
for(i=1 ; i<=N ; i++) {
now=i%2;
prev=(i-1)%2;
for(j=0 ; j<=H[i+1] ; j++) {
D[now][j][0]=D[prev][H[i]][j];
for(k=1 ; k<=H[i+2] ; k++) {
D[now][j][k]=D[now][j][k-1]+3;
if(j) D[now][j][k]=min(D[now][j][k],D[now][j-1][k-1]+5);
if(H[i]>=k && j>=k) D[now][j][k]=min(D[now][j][k],D[prev][H[i]-k][j-k]+7*k);
}
}
}
printf("%d",D[N%2][0][0]);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1400 KB |
Output is correct |
2 |
Correct |
0 ms |
1400 KB |
Output is correct |
3 |
Correct |
0 ms |
1400 KB |
Output is correct |
4 |
Correct |
0 ms |
1400 KB |
Output is correct |
5 |
Correct |
0 ms |
1400 KB |
Output is correct |
6 |
Correct |
0 ms |
1400 KB |
Output is correct |
7 |
Correct |
0 ms |
1400 KB |
Output is correct |
8 |
Correct |
0 ms |
1400 KB |
Output is correct |
9 |
Correct |
0 ms |
1400 KB |
Output is correct |
10 |
Correct |
1 ms |
1400 KB |
Output is correct |
11 |
Correct |
3 ms |
1400 KB |
Output is correct |
12 |
Correct |
3 ms |
1400 KB |
Output is correct |
13 |
Correct |
8 ms |
1400 KB |
Output is correct |
14 |
Correct |
10 ms |
1400 KB |
Output is correct |
15 |
Correct |
48 ms |
1400 KB |
Output is correct |
16 |
Correct |
46 ms |
1400 KB |
Output is correct |
17 |
Correct |
72 ms |
1400 KB |
Output is correct |
18 |
Correct |
65 ms |
1400 KB |
Output is correct |
19 |
Correct |
63 ms |
1400 KB |
Output is correct |
20 |
Correct |
71 ms |
1400 KB |
Output is correct |