#P5815. [CQOI2010] 扑克牌
[CQOI2010] 扑克牌
Description
You have types of cards. The number of cards of type is . There is also a special card type: joker, and its number is .
You can form one set of cards by taking one card from each type. You can also form one set by taking one joker and one card from every other type except one specific type. For example, when , there are valid sets in total: , , , .
Given , , and , your task is to form as many sets as possible. Each card can be used in at most one set (you may leave some cards unused).
Input Format
The first line contains two integers , , representing the number of card types and the number of jokers.
The second line contains integers , representing the number of cards of each type.
Output Format
Output only one integer: the maximum number of sets that can be formed.
3 4
1 2 3
3
Hint
Sample Explanation
The input shows that there are card of type , cards of type , cards of type , and jokers. At most three sets can be formed: , , . One joker remains, and all other cards are used up.
Constraints
For of the testdata, , , .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号