東京海上日動プログラミングコンテスト2024(AtCoder Beginner Contest 355)
G
Baseball
AtCoder
⌀ 2991
原题
翻译中…

Problem Statement

翻译中…

You are given a sequence $P=(P_1,P_2,\dots,P_N)$ of length $N$. Takahashi and Aoki will play a game using the sequence $P$.

翻译中…

First, Takahashi will choose $K$ distinct integers $x_1,x_2,\dots,x_K$ from $1,2,\dots,N$.

翻译中…

Next, Aoki will choose an integer $y$ from $1,2,\dots,N$ with a probability proportional to $P_y$. That is, the probability that integer $y$ is chosen is $\dfrac{P_y}{\sum_{y'=1}^N P_{y'}}$. Then, Aoki's score will be $\displaystyle \min_{i=1,2,\dots,K} |x_i-y|$.

翻译中…

Takahashi wants to minimize the expected value of Aoki's score. Find the expected value of Aoki's score when Takahashi chooses $x_1,x_2,\dots,x_K$ so that this value is minimized, multiplied by $\sum_{y'=1}^N P_{y'}$. It is guaranteed that the value to be printed is an integer.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 5 \times 10^4$
  • $1 \leq K \leq N$
  • $0 \leq P_i \leq 10^5$
  • $1 \leq \sum_{y'=1}^N P_{y'} \leq 10^5$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N K
P_1 P_2 \dots P_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
5 2
1 1 1 1 1
Output #1
3
The probabilities of Aoki choosing $1,2,\dots,N$ are all equal: $\frac{1}{5}$. If Takahashi chooses $x_1=2$ and $x_2=4$, then the expected value of Aoki's score will be $1 \times \frac{1}{5} + 0 \times \frac{1}{5} + 1 \times \frac{1}{5} + 0 \times \frac{1}{5} + 1 \times \frac{1}{5} = \frac{3}{5}$. If Takahashi chooses $x_1=2$ and $x_2=3$, then the expected value of Aoki's score will be $1 \times \frac{1}{5} + 0 \times \frac{1}{5} + 0 \times \frac{1}{5} + 1 \times \frac{1}{5} + 2 \times \frac{1}{5} = \frac{4}{5}$. No matter how Takahashi chooses, the expected value of Aoki's score cannot be smaller than $\frac{3}{5}$. Therefore, the minimum value is $\frac{3}{5}$, so print this value multiplied by $5$, which is $3$.
Input #2
5 1
0 0 1 0 0
Output #2
0
Input #3
1 1
100
Output #3
0
Input #4
20 7
4262 9522 2426 3823 7364 964 2743 2423 1955 5274 3684 847 363 35 278 3220 203 2904 6304 1928
Output #4
22809
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。