Codeforces Round 352 (Div. 1)
B
Robin Hood
Codeforces
2000
原题
← AC →
翻译中…

We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.

翻译中…

There are $*n*$ citizens in Kekoland, each person has $*c*_{*i*}$ coins. Each day, Robin Hood will take exactly $1$ coin from the richest person in the city and he will give it to the poorest person (poorest person right after taking richest's $1$ coin). In case the choice is not unique, he will select one among them at random. Sadly, Robin Hood is old and want to retire in $*k*$ days. He decided to spend these last days with helping poor people.

翻译中…

After taking his money are taken by Robin Hood richest person may become poorest person as well, and it might even happen that Robin Hood will give his money back. For example if all people have same number of coins, then next day they will have same number of coins too.

翻译中…

Your task is to find the difference between richest and poorest persons wealth after $*k*$ days. Note that the choosing at random among richest and poorest doesn't affect the answer.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*k*$ ($1 ≤ *n* ≤ 500 000, 0 ≤ *k* ≤ 10^{9}$) — the number of citizens in Kekoland and the number of days left till Robin Hood's retirement.

翻译中…

The second line contains $*n*$ integers, the $*i*$-th of them is $*c*_{*i*}$ ($1 ≤ *c*_{*i*} ≤ 10^{9}$) — initial wealth of the $*i*$-th person.

翻译中…

Output

翻译中…

Print a single line containing the difference between richest and poorest peoples wealth.

翻译中…

Note

翻译中…

Lets look at how wealth changes through day in the first sample.

翻译中…
  1. $[1, 1, 4, 2]$
  2. $[2, 1, 3, 2]$ or $[1, 2, 3, 2]$
翻译中…

So the answer is $3 - 1 = 2$

翻译中…

In second sample wealth will remain the same for each person.

翻译中…

样例

Input #1
4 1
1 1 4 2
Output #1
2
InputCopy OutputCopy
Input #2
3 1
2 2 2
Output #2
0
InputCopy OutputCopy
题目信息
题号
671B
时间限制
1 s
内存限制
256 MB
标签
二分
贪心

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