Decrease 2 max elements

AtCoder
IDabc368_b
Time2000ms
Memory256MB
Difficulty
You are given a sequence of $N$ positive integers $A = (A_1, A_2, \dots ,A_N)$. Takahashi repeats the following operation until $A$ contains one or fewer positive elements: * Sort $A$ in descending order. Then, decrease both $A_1$ and $A_2$ by $1$. Find the number of times he performs this operation. ## Constraints * $2 \leq N \leq 100$ * $1 \leq A_i \leq 100$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $\cdots$ $A_N$ [samples]
Samples
Input #1
4
1 2 3 3
Output #1
4

The process goes as follows:

*   After the 1st operation, $A$ is $(2, 2, 2, 1)$.
*   After the 2nd operation, $A$ is $(1, 1, 2, 1)$.
*   After the 3rd operation, $A$ is $(1, 0, 1, 1)$.
*   After the 4th operation, $A$ is $(0, 0, 1, 0)$. $A$ no longer contains more than one positive elements, so the process ends here.
Input #2
3
1 1 100
Output #2
2
API Response (JSON)
{
  "problem": {
    "name": "Decrease 2 max elements",
    "description": {
      "content": "You are given a sequence of $N$ positive integers $A = (A_1, A_2, \\dots ,A_N)$. Takahashi repeats the following operation until $A$ contains one or fewer positive elements: *   Sort $A$ in descending",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc368_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a sequence of $N$ positive integers $A = (A_1, A_2, \\dots ,A_N)$. Takahashi repeats the following operation until $A$ contains one or fewer positive elements:\n\n*   Sort $A$ in descending...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments