Get Min Cost
Amazon Kindle has several e-books that customers can purchase directly.
There are n books ordered sequentially numbered 1, 2,.., n, where the ith book
has a cost of cost[i]. A customer wants to purchase all the books, and kindle offers the customer a unique
scheme is described as the follows -
i. The customer can choose to buy the leftmost book individually for cost[i]. This book is then removed from the sequence.j. The customer can choose to buy the rightmost book individually for cost[j]. This book is then removed from the sequence.Given the cost of books cost, the cost to purchase the leftmost and rightmost books together, parCost, and the mx num of times the pairCost option can be applied k, find the min cost in which the customer can purchase all the books following the scheme above.
Complete the function getMinCost in the editor.
getMinCost has the following parameters:
int cost[n]: the cost of each bookint pairCost: the cost of purchase the leftmost and rightmost book togetherint k: the MAX NUM of times pairCost can be used
Returns
long int: the min cost to purchase all books
Endless thanks to our best friend for their kind help in sharing the source!
1Example 1

2Example 2
3Example 3
Constraints
Limits and guarantees your solution can rely on.
1 <= n <= 10^51 ≤ pairCost ≤ 10^91 ≤ k ≤ n1 <= cost[i] <= 10^9The cost array may not be in increasing order