Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started