Figure Skating Judging

시간 제한2초메모리 제한2048 MB

요약
n개의 점수 중 k개를 골라, 고른 점수들의 평균에서 각 점수가 벗어난 제곱 편차의 합을 최소로 만든다.
난이도

어려움10점 중 8점

유형
정렬, 누적 합, 그리디, 수학
정답자
아직 제출이 없습니다

문제

Anissa has just finished her figure skating routine and is anxiously awaiting her scores. The way scoring works at this specific event is a little peculiar - each figure skater is evaluated by several judges and the scores are averaged to give a final score.

Jolie is managing the software used to compile the scores and notices that a hacker has gotten in and inserted many fake evaluations. She knows exactly how many scores she should expect, so she will manually invalidate evaluations until the number of evaluations matches the number of judges she knows actually submitted evaluations.

The problem is, Jolie doesn’t know which evaluation to invalidate. She decides to use the following metric for assessing the badness of a collection of scores after invalidating enough to get the number of evaluations to match the number of judges:

  1. Compute the arithmetic mean of all the evaluations from the chosen collection.
  2. Compute the squared deviation of each evaluation in the chosen collection to the given arithmetic mean. That is, if the mean is μ\mu and a given evaluation is xx, the squared deviation is (μ−x)2(\mu - x)^2.
  3. Compute the sum of all squared deviations from step 2. This sum is the badness.

Compute the minimum badness over all possible collections of scores that can be obtained.

입력

The first line of input contains two integers, nn and kk (1≤k<n≤5⋅105)(1 \le k < n \le 5 \cdot 10^5), where nn is the total number of evaluations and kk is the expected number of evaluations.

Each of the next nn lines contains a single integer xx (1≤x≤106)(1 \le x \le 10^6). These are the evaluations.

출력

Output a single number, which is the minimum badness over all possible collections of scores that can be obtained. Answer is correct if it is within absolute or relative error of 10−610^{-6}.

예제2

  1. 예제 1

    입력
    4 3
    13
    13
    23
    13
    
    예상 출력
    0
    
  2. 예제 2

    입력
    5 2
    1
    2
    3
    4
    5
    
    예상 출력
    0.5