1D Party

AtCoder
IDarc120_e
Time2000ms
Memory256MB
Difficulty
There are $N$ people, Person $1$ through Person $N$, standing on a number line. Person $i$ is now at coordinate $A_i$ on the number line. Here, $A_1 < A_2 < A_3 < \dots < A_N$ and all $A_i$ are even numbers. We will now hold a party for $k$ seconds. During the party, each person can freely move on the number line at a speed of at most $1$ per second. (It is also allowed to move in the negative direction within the speed limit.) The people request that the following condition be satisfied for every integer $i$ such that $1 \le i \lt N$: * there is at least one moment during the party (including the moment it ends) when Person $i$ and Person $i + 1$ are at the same coordinate. Find the minimum $k$ for which there is a strategy that the people can take to satisfy all the conditions. We can prove that the answer is an integer under the Constraints of this problem. ## Constraints * $2 \le N \le 2 \times 10^5$ * $0 \le A_i \le 10^9$ * $A_1 < A_2 < A_3 < \dots < A_N$ * $A_i$ is an even number. ## Input Input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $A_3$ $\dots$ $A_N$ [samples]
Samples
Input #1
3
0 6 10
Output #1
5

During the party lasting $5$ seconds, each person should move as follows:

*   Person $1$: always moves in the positive direction at a speed of $1$.
*   Person $2$: moves in the positive direction at a speed of $1$ during the first $2$ seconds, then in the negative direction at a speed of $1$ during the remaining $3$ seconds.
*   Person $3$: always moves in the negative direction at a speed of $1$.

If they move in this way, Person $2$ and Person $3$ will be at the same coordinate exactly $2$ seconds after the beginning, and Person $1$ and Person $2$ will be at the same coordinate at the end of the party.  
Thus, they can satisfy all the conditions for $k = 5$. For smaller $k$, there is no strategy to satisfy all of them.
Input #2
5
0 2 4 6 8
Output #2
3

During the party lasting $3$ seconds, each person should, for example, move as follows:

*   Person $1$: always moves in the positive direction at a speed of $1$.
*   Person $2$: moves in the positive direction at a speed of $1$ during the first $2$ seconds, then in the negative direction at a speed of $1$ during the remaining $1$ second.
*   Person $3$: does not move at all.
*   Person $4$: moves in the negative direction at a speed of $1$ during the first $2$ seconds, then in the positive direction at a speed of $1$ during the remaining $1$ second.
*   Person $5$: always moves in the negative direction at a speed of $1$.
Input #3
10
0 2 4 6 8 92 94 96 98 100
Output #3
44
API Response (JSON)
{
  "problem": {
    "name": "1D Party",
    "description": {
      "content": "There are $N$ people, Person $1$ through Person $N$, standing on a number line. Person $i$ is now at coordinate $A_i$ on the number line.   Here, $A_1 < A_2 < A_3 < \\dots < A_N$ and all $A_i$ are even",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc120_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are $N$ people, Person $1$ through Person $N$, standing on a number line. Person $i$ is now at coordinate $A_i$ on the number line.  \nHere, $A_1 < A_2 < A_3 < \\dots < A_N$ and all $A_i$ are even...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments