Logo
(追記) (追記ここまで)

25946번 - Flags 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB230373116.757%

문제

Consider integer points on the $x$-axis. Every point with an $x$-coordinate of 1ドル$ or greater is associated with one of the colors: red or black. Specifically, as shown in Figure D.1, the color of the point with the $x$-coordinate of 1ドル$ is red, the next two points are black, the next three points are red, the next four points are black, and so on. In this way, every point with an $x$-coordinate of 1ドル$ or greater is associated with either red or black color.

Figure D.1 Colors of points on the $x$-axis

Let $c(x)$ denote the color of the point with coordinate $x$($≥ 1$). Then $c(x)$ is defined as follows.

$$ c(x) = \begin{cases} \text{red,} & \text{if} \displaystyle\sum_{i=0}^{2k}{i} < x \le \displaystyle\sum_{i=0}^{2k+1}{i}&\text{for }k = 0, 1, 2, \dots \\ \text{black,} & \text{otherwise} \end{cases} $$

There are $n$ flags at given points along the $x$-axis. For example, Figure D.2 shows a situation where five flags are erected. The $x$-coordinates of the $n$ flags are denoted as $f_1,ドル $f_2,ドル $\dots,ドル $f_n$.

Figure D.2 An example of five flags on the $x$-axis

Displeased that the colors of points where flags locate are not the same, Bob tries to move all the flags to the right the same distance, say $d,ドル so that all the flags locate on the red points. In other words, he wants to find $d$ such that for every $i$(1ドル ≤ i ≤ n$), $c(f_i + d)$ is red.

Given information about the locations of $n$ flags, write a program to find the smallest possible value of $d$.

입력

Your program is to read from standard input. The input starts with a line containing an integer $n$ (1ドル ≤ n ≤ 10^5$), where $n$ is the number of flags. Each of the next $n$ lines contains an $x$-coordinate in increasing order. The $i$-th line contains $f_i$ (1ドル ≤ i ≤ n,ドル 1ドル ≤ f_i ≤ 10^6$), the $x$-coordinate of the $i$-th flag

출력

Your program is to write to standard output. Print exactly one line. The line should contain the minimum distance $d$ by which all the flags must move to the right so that all the flags are on the red points.

제한

예제 입력 1

1
8

예제 출력 1

3

예제 입력 2

5
4
15
28
60
211

예제 출력 2

0

예제 입력 3

7
123
129
130
188
189
190
191

예제 출력 3

23

힌트

출처

ICPC > Regionals > Asia Pacific > Korea > Nationwide Internet Competition > Seoul Nationalwide Internet Competition 2022 D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /