fork download
  1. #include<bits/stdc++.h>
  2. #define M 200004
  3. using namespace std;
  4.  
  5. int n, a[M], dp[M];
  6.  
  7. int main()
  8. {
  9. ios_base::sync_with_stdio(0);
  10. cin.tie(0); cout.tie(0);
  11.  
  12. cin >> n;
  13. for(int i = 1; i < n; i++)
  14. cin >> a[i];
  15. dp[1] = a[1];
  16. dp[2] = a[1] + a[2];
  17. for(int i = 3; i < n; i++)
  18. dp[i] = min(dp[i - 1], dp[i - 2]) + a[i];
  19. cout << dp[n - 1];
  20. }
  21.  
Success #stdin #stdout 0s 5284KB
stdin
6
2
2
3
2
2
stdout
7