fork download
  1. #include <bits/stdc++.h>
  2. #define VuDucNam ios_base::sync_with_stdio(false);
  3. #define Lop9a6 cin.tie(NULL);
  4. #define THCSPhamVanDong cout.tie(NULL);
  5. #define ll long long
  6. #define el cout << '\n'
  7. #define sz(a) (ll) a.size()
  8. #define all(a) a.begin(), a.end()
  9. #define fi first
  10. #define se second
  11. #define fill(a, x) memset(a, x, sizeof(a))
  12. #define file(name) \
  13.   if (fopen(name ".inp", "r")) \
  14.   freopen(name ".inp", "r", stdin); \
  15.   freopen(name ".out", "w", stdout);
  16. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  17. #define RUNTIME cerr << "\nRuntime: " << TIME << "s.\n"
  18.  
  19. using namespace std;
  20.  
  21. const ll MOD = 1e9 + 7;
  22. const ll inf = LLONG_MAX;
  23.  
  24. int n,a[25005],dp[25005][6];
  25.  
  26. void solve()
  27. {
  28. cin >> n;
  29. for(int i=1;i<n;++i)
  30. cin >> a[i];
  31. dp[1][0]=a[1];
  32. dp[1][1]=a[1];
  33. for(int i=2;i<n-1;++i){
  34. dp[i][0]=dp[i-1][1];
  35. dp[i][1]=min(dp[i-1][0],dp[i-1][1]) + a[i];
  36. }
  37. int ans=min(dp[n-2][0],dp[n-2][1]) + a[n-2];
  38. cout << ans;
  39. el;
  40. }
  41.  
  42. int main()
  43. {
  44. VuDucNam Lop9a6 THCSPhamVanDong
  45. // file();
  46. solve();
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
0