Minimum Coin spent with K shops

There are K shops in a row. You can spend minimum of A[i] amount at ith shop, i = (0,K).

The shopping has to be sequential and every shop you skip a minimum amount has to be given to skip the shop.
You cannot skip 1st and last shop and you can skip max of 3 shops in continuation.

Determine minimum amount of money spent after all k shops passed.

Input:

K x
K seperated integer value that has to be spend at each shop.

Output: y (min amount )

2 <= K <= 210^5
1 <= x <= 2
10^5
1 <= A[i] <= 2*10^5

Input:
5 2
1 2 3 4 5

**Output
12

Comments (1)