#abc358d. D - Souvenirs
D - Souvenirs
Score : points
问题陈述
AtCoder Land的一家纪念品商店出售个盒子。
这些盒子编号为到,第个盒子的价格为日元,并且包含块糖果。
高桥想要从个盒子中购买个,并将每个盒子分别送给名为的个人。
在这里,他想要购买能够满足以下条件的盒子:
- 对于每个,第个人将获得一个至少包含块糖果的盒子。
请注意,不允许将多个盒子送给一个人,或者将同一个盒子送给多个人。
确定是否可能购买个盒子以满足条件,如果可能,请找出高桥需要支付的最低总金额。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
A souvenir shop at AtCoder Land sells boxes.
The boxes are numbered to , and box has a price of yen and contains pieces of candy.
Takahashi wants to buy out of the boxes and give one box each to people named .
Here, he wants to buy boxes that can satisfy the following condition:
- For each , person is given a box containing at least pieces of candy.
Note that it is not allowed to give more than one box to a single person or to give the same box to multiple people.
Determine whether it is possible to buy boxes that can satisfy the condition, and if it is possible, find the minimum total amount of money Takahashi needs to pay.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
If it is possible to buy boxes that can satisfy the condition, print the minimum total amount of money Takahashi needs to pay. Otherwise, print .
Sample Input 1
4 2
3 4 5 4
1 4
Sample Output 1
7
Takahashi can buy boxes and , and give box to person and box to person to satisfy the condition.
In this case, he needs to pay yen in total, and it is impossible to satisfy the condition by paying less than yen, so print .
Sample Input 2
3 3
1 1 1
1000000000 1000000000 1000000000
Sample Output 2
-1
Sample Input 3
7 3
2 6 8 9 5 1 11
3 5 7
Sample Output 3
19