Question: You are given 2 arrays A and B , each of size N . You are now standing at index N and want to move
You are given arrays A and B each of size N
You are now standing at index N and want to move to index by performing the following operation one or more times until you reach index :
Let's say that the element you are currently standing on is i The cost of standing at index i will be equal to Ai
Choose index j such that j i
If you want to move from index i to index j the cost of passing between them will be equal to Bj
Find the minimum cost to move from index N to index Since the answer can be very large, return it modulo
Input Format
The first line contains an integer, N denoting the number of elements in A and B
Each line i of the N subsequent lines where i N contains an integer describing Ai
Each line i of the N subsequent lines where i N contains an integer describing Bi
Input
Constraints
N
Ai g
Bi
Sample Test Cases
Case
Input:
Output:
Explanation:
Given N A B
We can perform the following operations as:
We are currently standing at index with a cost of A We will select the index and the cost of passing between index to index is equal to B Then total cost till now is equal to
In second move we are currently standing at index with a cost of A we can select the index and the cost of passing between index and index is equal to B The total cost till now is equal to
Hence, total cost is equal to
Input
Case
Input:
Output:
Case
Input:
Output:
Explanation:
Given
We can perform the following operations as:
Ve are currently standing at index with a cost of He wi select the index and the cost of passing between index to index is equal to Then total cost till now is equal to
In second move we are currently standing at index with a cost of we can select the index and the cost of passing between index and index is equal to The total cost till now is equal to
Hence, total cost is equal to
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
