QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 2048 MB 満点: 100

#14442. 花式滑冰評分

統計

Anissa 剛剛完成了她的花式滑冰表演,正焦急地等待著她的分數。這項賽事的評分方式有些獨特——每位花式滑冰選手由多位裁判進行評估,並將分數取平均值作為最終得分。

Jolie 負責管理編譯分數的軟體,她發現有駭客入侵並插入了許多虛假評分。她確切地知道應該預期多少個分數,因此她將手動刪除評分,直到剩餘的評分數量與她所知實際提交評分的裁判人數相符。

問題在於,Jolie 不知道該刪除哪些評分。她決定使用以下指標來評估在刪除足夠多的評分以匹配裁判人數後,剩餘分數集合的「糟糕程度」(badness):

  1. 計算所選集合中所有評分的算術平均值。
  2. 計算所選集合中每個評分與上述算術平均值的平方差。也就是說,如果平均值為 $\mu$,而某個評分為 $x$,則平方差為 $(\mu - x)^2$。
  3. 計算步驟 2 中所有平方差的總和。此總和即為「糟糕程度」。

請計算在所有可能獲得的分數集合中,最小的糟糕程度。

輸入格式

輸入的第一行包含兩個整數 $n$ 和 $k$ ($1 \le k < n \le 5 \cdot 10^5$),其中 $n$ 是總評分數量,$k$ 是預期的評分數量。

接下來的 $n$ 行,每行包含一個整數 $x$ ($1 \le x \le 10^6$),代表這些評分。

輸出格式

輸出一個數字,代表在所有可能獲得的分數集合中,最小的糟糕程度。如果答案的絕對誤差或相對誤差在 $10^{-6}$ 以內,則視為正確。

範例

範例輸入 1

4 3
13
13
23
13

範例輸出 1

0

範例輸入 2

5 2
1
2
3
4
5

範例輸出 2

0.5

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.