問題一覧 > 通常問題

No.731 Love for Arithmetic Progressions

レベル : / AI推定難易度 : 1300 / 実行時間制限 : 1ケース 1.500秒 / メモリ制限 : 512 MB / 小数誤差許容問題 絶対誤差または相対誤差が $10^{-6}$ 以下。ただし、ジャッジ側の都合で500桁未満にしてください
タグ : (AC するまで非表示) / 解いたユーザー数 125
作問者 : りあん / テスター : ixmel
お気に入りにしたユーザー ProblemId : 1169 / 自分の提出
問題文最終更新日: 2018-09-07 17:19:49
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 199 (順位表) の他の問題:

Problem Statement

Rian, who loves arithmetic progressions, found a sequence with $N$ elements by the roadside.

Because Rian loves arithmetic progressions so much, he decided to ask the Sequence Old Man, who can change the value of each element of a sequence, to turn the sequence he found into an arithmetic progression.

However, the Sequence Old Man charges a cost of $(a_i - b_i)^2$ to change the $i$-th element $a_i$ of the sequence to $b_i$. (Also, he will change the value of each element at most once.)

For example, the cost of changing the sequence {3, 3, 4} to {5, 5, 5} is 4 + 4 + 1 = 9, and the cost of changing it to {3, 3.5, 4} is 0 + 0.25 + 0 = 0.25.

Rian wants to obtain an arithmetic progression at as low a cost as possible, so find the first term $b_1$ and the common difference $d$ that minimize the cost, as well as the cost $c$ incurred in that case.

Input

$N$
$a_1 \ a_2 \ \ldots \ a_N$

The first line contains the number of elements $N$ of the sequence.

The second line contains the values $a_i \ (1 \le i \le N)$ of the elements of the sequence, separated by spaces.

All inputs are integers and satisfy the following constraints.

  • $2 \le N \le 1000$
  • $0 \le a_i \le 10^5$

Output

On the first line, output the first term $b_1$ and the common difference $d$ of the resulting arithmetic progression that minimizes the cost, separated by a space.

On the second line, output the cost $c$ incurred in that case.

For each value, an error of at most $10^{-6}$ is allowed.

Print a newline at the end.

Sample

Sample 1
Input
3
3 3 4
Output
2.83333333333333 0.5
0.166666666666667
Sample 2
Input
5
0 0 0 0 10000
Output
-2000 2000
40000000

$b_1$ may be negative.

Sample 3
Input
7
6 5 4 3 2 1 0
Output
6 -1
0

$d$ may be negative, and $c$ may be zero.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。