Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!