Get Closer

AtCoder
IDawtf2025_c
Time2000ms
Memory256MB
Difficulty
There are balls with integers from $1$ to $N$ written on them. Specifically, there are $A_i$ balls with integer $i$ ($1 \leq i \leq N$) written on them. Define $S=A_1+A_2+\cdots+A_N$. Here, it is guaranteed that $S$ is a positive even number. Divide the $S$ balls into $S/2$ pairs. The integers written on the two balls in a pair must be different. It can be proved that such pairing is possible under the constraints of this problem. For each pair, perform the following operation: * Let the integers written on the two balls be $x$ and $y$ ($x < y$). Replace the numbers written on these balls with $x+0.5$ and $y-0.5$, respectively. After completing the operation for all pairs, let $d$ be the maximum number of balls with the same number written on them. Find the minimum possible value of $d$. Solve $T$ test cases for each input. ## Constraints * $1 \leq T \leq 125000$ * $2 \leq N \leq 250000$ * $0 \leq A_i \leq 10^9$ * $S=A_1+A_2+\cdots+A_N$ is a positive even number. * $A_i \leq S/2$ * The sum of $N$ over all test cases in each input does not exceed $250000$. * All input values are integers. ## Input The input is given from Standard Input in the following format: $T$ $case_1$ $case_2$ $\vdots$ $case_T$ Each test case is given in the following format: $N$ $A_1$ $A_2$ $\cdots$ $A_N$ [samples]
Samples
Input #1
4
4
1 2 2 1
4
2 2 5 1
7
101 2 203 304 5 106 107
20
239276621 320064891 910500852 164832983 245532750 198319686 715892722 967824729 769431650 80707349 459924867 257261830 777045523 583882654 950300098 438099970 322288793 532405019 256358887 45539860
Output #1
2
6
203
613287276

Consider the first test case. Let $(x,y)$ denote a pair of balls with integers $x,y$ written on them.
For example, if we pair as $(1,3),(2,3),(2,4)$, the numbers written on the balls after the operation are $1.5,2.5,2.5,2.5,2.5,3.5$. The maximum number of balls with the same number written on them is $d=4$.
On the other hand, if we pair as $(1,2),(2,3),(3,4)$, the numbers written on the balls after the operation are $1.5,1.5,2.5,2.5,3.5,3.5$. The maximum number of balls with the same number written on them is $d=2$.
$d$ cannot be made smaller than $2$, so the answer is $2$.
API Response (JSON)
{
  "problem": {
    "name": "Get Closer",
    "description": {
      "content": "There are balls with integers from $1$ to $N$ written on them. Specifically, there are $A_i$ balls with integer $i$ ($1 \\leq i \\leq N$) written on them. Define $S=A_1+A_2+\\cdots+A_N$. Here, it is guar",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "awtf2025_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are balls with integers from $1$ to $N$ written on them. Specifically, there are $A_i$ balls with integer $i$ ($1 \\leq i \\leq N$) written on them.\nDefine $S=A_1+A_2+\\cdots+A_N$. Here, it is guar...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments