Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are n hills of some height. On first hill there lives two friends and on nth hill there lives a monster. One day monster

image text in transcribed

There are n hills of some height. On first hill there lives two friends and on nth hill there lives a monster. One day monster took one of the two friends to his home (nth hill). On knowing this the other friend went to rescue his friend. To reach the nth hill the friend has to follow this process: if he is currently on hill i, he can jump to one of the following hills i+1,i+2,....i+k. Here, a cost of |h-h;| is incurred, where j is the hill to land on and h; and h; are heights of ith and jth hill respectively). You are asked to print the minimum possible total cost incurred by the time the friend reaches nth hill. Input: First line contains n and k. Second line contains n integers, the height of hills. Output: Print the minimum time required. Constraints All values in input are integers. 2sNs1045 1 sks100 1sh s10000 SAMPLE INPUT SAMPLE OUTPUT 30 5 3 10 30 40 50 20 Explanation If we follow the path 1 + 2 + 5, the total cost incurred would be 10-30+30-201=30

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_2

Step: 3

blur-text-image_3

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

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions

Question

Find P(Z Answered: 1 week ago

Answered: 1 week ago