#P5815. [CQOI2010] 扑克牌

[CQOI2010] 扑克牌

Description

You have nn types of cards. The number of cards of type ii is cic_i. There is also a special card type: joker, and its number is mm.

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 n=3n=3, there are 44 valid sets in total: {1,2,3}\{1,2,3\}, {J,2,3}\{J,2,3\}, {1,J,3}\{1,J,3\}, {1,2,J}\{1,2,J\}.

Given nn, mm, and cic_i, 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 nn, mm, representing the number of card types and the number of jokers.

The second line contains nn integers cic_i, 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 11 card of type 11, 22 cards of type 22, 33 cards of type 33, and 44 jokers. At most three sets can be formed: {1,J,3}\{1,J,3\}, {J,2,3}\{J,2,3\}, {J,2,3}\{J,2,3\}. One joker remains, and all other cards are used up.

Constraints

For 50%50\% of the testdata, 2n52 \le n \le 5, 0m1060 \le m \le 10^6, 0ci2000 \le c_i \le 200.

For 100%100\% of the testdata, 2n502 \le n \le 50, 0m,ci5×1080 \le m,c_i \le 5 \times 10^8.

Translated by ChatGPT 5