Iamtui1010

nktick.cpp

Oct 27th, 2022
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4.  
  5. #define long long long
  6. #define nln '\n'
  7.  
  8. const long INF = 1e18;
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14. cin.tie(0)->sync_with_stdio(0);
  15. long n;
  16. cin >> n;
  17. vector<long> a(n+1, 0);
  18. for (long i = 1; i <= n; ++i)
  19. cin >> a[i];
  20. vector<long> t(n, 0);
  21. for (long i = 1; i <= n-1; ++i)
  22. cin >> t[i];
  23.  
  24. vector<long> dp(n+1, 0);
  25. dp[0] = 0;
  26. dp[1] = min(a[1], t[1]);
  27.  
  28. for (long i = 2; i <= n; ++i)
  29. dp[i] = min(dp[i-1]+a[i], dp[i-2]+t[i-1]);
  30.  
  31. cout << dp[n] << nln;
  32.  
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment