fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define endl "\n"
  4. #define int long long
  5. #define faster() ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  6. #define MOD 1000000007
  7.  
  8. void solve(){
  9. int n ; cin >> n ;
  10. int t[n + 1] , r[n + 1];
  11. for(int i = 1 ; i <= n ; i++) cin >> t[i];
  12. for(int i = 1 ; i <= n - 1 ; i++) cin >> r[i];
  13.  
  14. int dp[n + 1] = {}; // dp[i] : thoi gian toi thieu de phuc vu tu nguoi thu 1 => nguoi thu i
  15. dp[1] = t[1] ; // nguoi dau tien tu mua ve
  16. for(int i = 2 ; i <= n ; i++){
  17. dp[i] = min(dp[i - 1] + t[i] , dp[i - 2] + r[i - 1]);
  18. }
  19. cout << dp[n] << endl;
  20. }
  21.  
  22. signed main(){
  23. faster();
  24. int test = 1;
  25. // cin >> test ;
  26. while(test--){
  27. solve();
  28. }
  29. }
Success #stdin #stdout 0.01s 5276KB
stdin
4
5 7 8 4
50 50 50 
stdout
24