# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

There is a shop named Chocolove in the Codeland. There are many chocolates in the shop. Each chocolate has its own taste value. You want to take some chocolates from this shop. But the chocolates are not free. You have to pay.
If you take chocolate **i** and the previous chocolate you took is **j**, the cost of taking chocolate **i** is the difference between **i*T _{j}** and

Now you want to know what is the minimum amount of money you have to pay if you take

The first line of the input contains an integer **N**, the number of chocolates. The next line contains **N** integers separated by a space, **i**th integer denotes the taste value of **i**th chocolate.

The next line contains an integer **Q**, the number of queries. The next **Q** lines will contain values denoting each query. In each query, there will be an integer **x**, the number of chocolates you want to take from the shop.

**Constraints:1 <= N <= 190 <= Taste Value <= 10**

For each query, print the minimum amount of money you have to pay in a single line if you take **x** chocolates from the shop

Input | Output |
---|---|

3 17 90 81 2 3 2 | 86 30 |

In the first query, one of the best ways is taking chocolates in this order: 2, 1, 3. |

67% Solution Ratio

m1n2o3Earliest,

mahdi.hasnatFastest, 0.3s

m1n2o3Lightest, 81 MB

m1n2o3Shortest, 807B

Login to submit