
Little Lana and little Fran are visiting a chocolate factory. They have seen how chocolate is made, tasted many chocolates, and now they want to buy some of the chocolates.
In the shop, there are
Fran found a way to split the cost in the shop:
- If the chocolate is cheaper than
kunas, Lana will pay for it. - Otherwise, Lana will pay
kunas, and Fran will pay the rest, that is kunas.
Let's denote
Help her choose the chocolates and determine the minimum value of the expression
Input Specification
The first line contains two integers
The second line contains
The following
Output Specification
Print
Constraints
Subtask | Points | Constraints |
---|---|---|
No additional constraints. |
Sample Input 1
5 2
1 9 22 10 19
18 4
5 2
Sample Output 1
34
-21
Explanation for Sample Output 1
In the first query, Lana can take chocolates with prices
In the second query, Lana will choose chocolates with prices
Sample Input 2
7 4
1 5 4 3 7 11 9
5 4
5 7
7 3
4 5
Sample Output 2
4
16
7
1
Sample Input 3
3 3
5 6 7
10 1
5 3
3 3
Sample Output 3
5
12
0
Comments