#P5815. Maximum Sets Formation with Joker Substitution

    ID: 19043 Type: Default 1000ms 256MiB

Maximum Sets Formation with Joker Substitution

Maximum Sets Formation with Joker Substitution

You are given \( n \) types of cards. For the \( i\)-th type, you have \( c_i \) cards. Additionally, you have a special card called joker and you have \( m \) copies of it.

You can form a set in one of the following two ways:

  • Use one card of each type, forming a complete set \( \{1,2,\dots,n\} \).
  • Use a joker to substitute one missing card and use one card from every other type. In other words, for some \( j \) (\( 1 \le j \le n \)), you form a set \( \{J\} \cup \{\text{all cards except type } j\} \).

For example, when \( n = 3 \), the four legal sets are:

\[ \{1,2,3\},\quad \{J,2,3\},\quad \{1,J,3\},\quad \{1,2,J\} \]

Your task is to form as many sets as possible. Note that each card (including each joker) can be used at most once.

Hint: If you want to form \( x \) sets, and let \( b_i \) be the number of sets in which type \( i \) is replaced with a joker, then for each \( i \) the total usage of type \( i \) cards is \( x - b_i \). Hence, you must have \( x - b_i \le c_i \) and \( \sum_{i=1}^{n} b_i \le m \). An optimal strategy is to set \( b_i = \max(0, x-c_i) \). Therefore, the maximum \( x \) satisfies \[ \sum_{i=1}^{n} \max(0,x-c_i) \le m. \]

inputFormat

The first line contains two integers \( n \) and \( m \) (the number of card types and the number of jokers).

The second line contains \( n \) integers \( c_1, c_2, \dots, c_n \) representing the count of each type of card.

outputFormat

Output a single integer, the maximum number of sets you can form.

sample

3 0
2 2 2
2

</p>