#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <utility>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
int a[305], n;
int dp[305][205][205];
int f(int pos, int t1, int t2){
if(t1 < 0 || t2 < 0) return 1e9;
if(pos == n) return 0;
if(~dp[pos][t1][t2]) return dp[pos][t1][t2];
int ret = min(f(pos, t1 - 1, t2) + 3, f(pos, t1 - 1, t2 - 1) + 5);
ret = min(ret, f(pos+1, t2-t1, a[pos+2] - t1) + t1 * 7);
return dp[pos][t1][t2] = ret;
}
int main(){
scanf("%d",&n);
memset(dp,-1,sizeof(dp));
for(int i=0; i<n; i++){
scanf("%d",&a[i]);
}
printf("%d",f(0, a[0], a[1]));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
51792 KB |
Output is correct |
2 |
Correct |
3 ms |
51792 KB |
Output is correct |
3 |
Correct |
5 ms |
51792 KB |
Output is correct |
4 |
Correct |
7 ms |
51792 KB |
Output is correct |
5 |
Correct |
0 ms |
51792 KB |
Output is correct |
6 |
Correct |
3 ms |
51792 KB |
Output is correct |
7 |
Correct |
3 ms |
51792 KB |
Output is correct |
8 |
Correct |
5 ms |
51792 KB |
Output is correct |
9 |
Correct |
4 ms |
51792 KB |
Output is correct |
10 |
Correct |
7 ms |
51792 KB |
Output is correct |
11 |
Correct |
19 ms |
52196 KB |
Output is correct |
12 |
Correct |
13 ms |
51792 KB |
Output is correct |
13 |
Correct |
29 ms |
52248 KB |
Output is correct |
14 |
Correct |
36 ms |
52476 KB |
Output is correct |
15 |
Correct |
136 ms |
53156 KB |
Output is correct |
16 |
Correct |
134 ms |
53044 KB |
Output is correct |
17 |
Correct |
205 ms |
53560 KB |
Output is correct |
18 |
Correct |
201 ms |
53508 KB |
Output is correct |
19 |
Correct |
180 ms |
53408 KB |
Output is correct |
20 |
Correct |
208 ms |
53552 KB |
Output is correct |