Rest in Intervals

  • I have appeared for an online coding quiz and i have tackled this question. Though i couldnt be able to solve it but now when am trying

    As question demands for the best possible case i think recussion will be used here. but i couldnt able to deduce the recursive function of it .

    You have participated in a race. You are given a bed map that contains N intervals of the race (A1,A2,A3.....An) which denotes that you have run Ai meter in the ith time interval. If you rest in the jth interval then your speed increases M times for the next D intervals. The speed of any interval can never be increased more than M times.
    If you rest during any time interval then it means that you ran for 0 meters in that time interval. Therefore you decide that now you wil rest exactly K time intervals

    Your task is to optimize select exactly k time intervals of rest such that you can cover maximum distance.

    Test Case:

    1. N=5 K=2 D=2 M=10
      1 2 3 4 5

    as take rest in 1st and 3rd interval answer will look like =0+210+0+410+5*10=110

Log in to reply