#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
int n;
cin>>n;
vector<int> a(n),dp(n);
for(int i=0;i<n;i++){
cin>>a[i];
dp[i]=a[i];
if(i>2){
dp[i]+=min(dp[i-1],min(dp[i-2],dp[i-3]));
}
}
if(n>2)cout<<min(dp[n-1],min(dp[n-2],dp[n-3]));
else if(n>1)cout<<min(dp[n-1],dp[n-2]);
else cout<<dp[n-1];
}
Comments
Post a Comment