#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAX_N = 302;
const int MAX_H = 202;
const int INF = 1e9+7;
int n,dp[MAX_N][MAX_H],a[MAX_N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(int i=0; i<MAX_N; i++)
{
for(int j=0; j<MAX_H; j++)
{
dp[i][j] = INF;
}
}
for(int i=1; i<=n; i++) cin>>a[i];
for(int j=0; j<=a[1]; j++)
{
dp[1][j] = (a[1]-j)*3;
}
if(n == 1)
{
cout<<dp[n][0]<<endl;
return 0;
}
for(int x=0; x<=a[2]; x++)
{
int mini = min(a[2]-x,a[1]);
dp[2][x] = (mini*5+(a[1]-mini)*3+(a[2]-x-mini)*3);
}
if(n == 2)
{
cout<<dp[n][0]<<endl;
return 0;
}
int tmp,mini;
for(int i=3; i<=n; i++)
{
for(int x=0; x<=a[i]; x++)
{
int last_val = a[i-2];
if(a[i-1] < last_val) last_val = a[i-1];
if(a[i]-x < last_val) last_val = x;
for(int j=0; j<=last_val; j++)
{
tmp = dp[i-2][j]+j*7;
mini = min(a[i]-x-j,a[i-1]-j);
tmp += mini*5;
tmp += (a[i-1]-j-mini)*3+(a[i]-x-j-mini)*3;
dp[i][x] = min(dp[i][x],tmp);
}
}
}
cout<<dp[n][0]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
444 KB |
Output is correct |
3 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |