Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem StatementThe PhonePe headquarters, a futuristic marvel with interconnected towers of various heights, is being protected by Spider - Man. The heights of these towers

Problem StatementThe PhonePe headquarters, a futuristic marvel with interconnected towers of various heights, is being protected by Spider-Man. The heights of these towers are represented as an array heights with n elements, where heights[i] represents the height of the i-th tower from left to right.Spider-Man starts on the first tower (index 0) and needs to reach the last tower (index n-1) to deal with a security alert.Spider-Man has two ways to move between towers:Use Spider Silk:Spider-Man can spend x energy points to use his spider silk. This allows him to move up to k towers to the right, landing on the first tower that is higher than his current position. If there is no taller tower within the next k towers, he can't use the spider silk in this way.Jump:Alternatively, Spider-Man can spend y energy points to jump to one of the next two towers to the right.TaskHelp Spider-Man find the minimum energy points required to reach the last tower and uphold the security of PhonePe headquarters.Input FormatThe first line of the input format contains an integer n denoting the size of the array heights.The following line contains n space-separated integers denoting the elements of the array heights.The following line contains an integer k representing Spider-Man's field of vision for the spider silk method.The next two lines contain the integers x and y representing the energy cost for using the spider silk and jumping, respectively.Constraints(1\leq heights.length \leq 10^5)(1\leq heights[i]\leq 10^4)(1\leq k \leq 10^5)(1\leq x, y \leq 10^3)Output FormatPrint an integer denoting the minimum energy points Spider-Man requires to reach the last tower and uphold the security of PhonePe headquarters.Consider all possible edge cases, such as when Spider-Man can't find a taller tower within his vision range or when only jumps are necessary.Optimize your solution to ensure that it runs efficiently.Sample Input 16
103040503060
5
2
2Sample Output 16Explanation for Sample Output 1At first, Spider-Man will go to the 3rd tower (2nd index) using Jump:Total Energy points =2In the next move, Spider-Man will go to the 5th tower (4th index) using Jump:Total Energy points =2+2=4In the next move, Spider-Man will go to the 6th tower (5th index) using Jump:Total Energy points =4+2=6So,6 will be the minimum energy Spider-Man will require to reach the last tower.Sample Input 26
154335
3
10
6Sample Output 216Explanation for Sample Output 2At first, Spider-Man will go to the 3rd tower (2nd index) using Jump:Total Energy points =6In the next move, Spider-Man will go to the 6th tower (5th index) using Spider Silk:Total Energy points =6+10=16So,16 will be the minimum energy Spider-Man will require to reach the last tower.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

More Books

Students also viewed these Databases questions

Question

2. Avoid basing most of a report-card grade on one test.

Answered: 1 week ago

Question

4. Explain how to use fair disciplinary practices.

Answered: 1 week ago

Question

3. Give examples of four fair disciplinary practices.

Answered: 1 week ago