fork download
  1. #include<bits/stdc++.h>
  2. #define M 60004
  3. using namespace std;
  4.  
  5. int n;
  6. int t[M], r[M];
  7. long long dp[M];
  8.  
  9. int main()
  10. {
  11. ios_base::sync_with_stdio(0);
  12. cin.tie(0); cout.tie(0);
  13. #define name "baitap"
  14.  
  15. cin >> n;
  16. for(int i = 1; i <= n; i++)
  17. cin >> t[i];
  18. for(int i = 1; i < n; i++)
  19. cin >> r[i];
  20. dp[1] = t[1];
  21. dp[2] = min(t[1] + t[2], r[1]);
  22. for(int i = 3; i <= n; i++)
  23. dp[i] = min(dp[i - 1] + t[i], dp[i - 2] + r[i - 1]);
  24. cout << dp[n];
  25. }
  26.  
Success #stdin #stdout 0.01s 5268KB
stdin
5
2 5 7 8 4
4 9 10 10
stdout
18