問題一覧 > 通常問題

No.972 Score of a Selection

レベル : / AI推定難易度 : 1700 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 134
作問者 : 沙耶花 / テスター : shibh308
お気に入りにしたユーザー ProblemId : 3635 / 自分の提出
問題文最終更新日: 2020-01-18 00:11:19
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 234 (順位表) の他の問題:

Problem Statement

When you choose $k$ elements ( $k \ge 1$ ) from a sequence of positive integers $a_1,...,a_N$ consisting of $N$ elements and call them $b_1,...,b_k$,
the score $S$ you obtain is expressed as follows, using the median $m$ (described below) of the $k$ elements.
\[ S = \sum_{i=1}^{k} (b_i - m) \] Find the maximum value of $S$.
It can be shown that the answer is always an integer. Output it as an integer.

Note: The median $m$ of $k$ numbers is expressed as follows, where $x_1,...,x_k$ is the sequence obtained by sorting them in ascending order. \[ m = \begin{cases} \ x_{\frac{k+1}{2}} \ (kが奇数) \\ \ \frac{1}{2} \times (x_{\frac{k}{2}} + x_{\frac{k}{2} +1 }) \ (kが偶数) \end{cases} \]

Input

$N$
$a_1\ a_2\ ...\ a_N$

  • $1 \le N \le 2\times 10^5$
  • $1 \le a_i \le 10^9 $
  • All inputs are integers.

Output

Output the answer.
Print a newline at the end.

Sample

Sample 1
Input
5
1 2 3 4 5
Output
2

When $b=\{1,2,5\}$, the score is $(1-2)+(2-2)+(5-2)=2$. This is the maximum value.

Sample 2
Input
4
7 7 7 9
Output
2

The maximum value can be achieved by choosing all the elements.

Sample 3
Input
10
3 8 9 7 2 2 10 10 35 5
Output
37

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