#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;
const int N=303;
const int M=202;
int dp[N][M][M],arr[N],n;
int rec(int pos,int a1,int a2){
if(pos>=n)
return min(a1,a2)*5+(max(a1,a2)-min(a1,a2))*3;
int &ret=dp[pos][a1][a2];
if(~ret)
return ret;
ret=INF;
int val=min(arr[pos],min(a1,a2));
if(val==a2)
ret=min(ret,rec(pos+1,arr[pos]-val,a1-val)+val*7);
if(a1 and a2)
ret=min(ret,rec(pos,a1-1,a2-1)+5);
if(a2)
ret=min(ret,rec(pos,a1,a2-1)+3);
return ret;
//a2 a1 a[pos]
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",arr+i);
memset(dp,-1,sizeof dp);
printf("%d\n",rec(2,arr[1],arr[0]));
return 0;
}
Compilation message
skyline.cpp: In function 'int main()':
skyline.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
25 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
skyline.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
27 | scanf("%d",arr+i);
| ~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
48748 KB |
Output is correct |
2 |
Correct |
29 ms |
48748 KB |
Output is correct |
3 |
Correct |
22 ms |
48748 KB |
Output is correct |
4 |
Correct |
34 ms |
48748 KB |
Output is correct |
5 |
Correct |
22 ms |
48748 KB |
Output is correct |
6 |
Correct |
22 ms |
48748 KB |
Output is correct |
7 |
Correct |
23 ms |
48748 KB |
Output is correct |
8 |
Correct |
23 ms |
48748 KB |
Output is correct |
9 |
Correct |
24 ms |
48748 KB |
Output is correct |
10 |
Correct |
26 ms |
48748 KB |
Output is correct |
11 |
Correct |
41 ms |
49260 KB |
Output is correct |
12 |
Correct |
28 ms |
48876 KB |
Output is correct |
13 |
Correct |
42 ms |
49260 KB |
Output is correct |
14 |
Correct |
55 ms |
49260 KB |
Output is correct |
15 |
Correct |
136 ms |
49520 KB |
Output is correct |
16 |
Correct |
127 ms |
49536 KB |
Output is correct |
17 |
Correct |
194 ms |
48760 KB |
Output is correct |
18 |
Correct |
184 ms |
49388 KB |
Output is correct |
19 |
Correct |
171 ms |
49604 KB |
Output is correct |
20 |
Correct |
192 ms |
49388 KB |
Output is correct |