Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
1 like 0 dislike
1,454 views

There are 'n' stones in a row from 0 to n-1. For every ith stone , there are 2 values associated with it, a[i] and b[i] . You have to remove all the stones from the row one by one. Removing the ith stone follows the rule :

 

  1.  

    If (i-1)th and (i+1)th stones are still present , then , cost of removing the ith stone is b[i].

     

  2.  

    if either (i-1)th or (i+1)th stone is present , then cost of removing the ith stone is a[i].

     

  3.  

    if neither (i-1)th nor (i+1)th stone is present , the cost of removing the ith stone is 0.

     

 

Find the minimum total cost of removing all the stones.

 

Constraints :
1 <= n <= 50000
1 <= a[i] , b[i] <= 1000

in Online Assessments by Expert (108,280 points) | 1,454 views

Please log in or register to answer this question.