You are given \(N\) destinations that must be covered in \(N\) days in any order. Any \(i^{th}\) (\(1\le i\le N\)) destination can be traveled on any \(j^{th}\ (1\le j\le N)\) day. There are only two ways to reach any destination and that is by cars or buses. The cost of reaching to the \(i^{th}\) destination by cars \((C_1,C_2,.....C_n)\) and buses \((B_1, B_2,.....B_n)\) are given.
The only constraint is that you cannot use the same way of travel on two consecutive days. Determine the minimum total cost that you need to pay in reaching all \(N\) destinations.
Input format
- First line: A single integer \(N\)
- Second line: \(N\) space-separated integers denoting the cost of reaching the destination by cars
- Third line: \(N\) space-separated integers denoting the cost of reaching the destination by buses
Output format
Print the minimum total cost that you need to pay in reaching all \(N\) destinations.
Constraints
We can go on two days by car i.e on first day and last day, and on the other three days by bus to get the minimum cost which is 29.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor