0
点赞
收藏
分享

微信扫一扫

codeforces 810A Straight «A»


网址:​​点击打开链接​​


A. Straight «A»



time limit per test



memory limit per test



input



output


Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.

1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8.

[8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8.

has to have mark k.

n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.


Input



n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100)

n integers a1, a2, ..., an (1 ≤ ai ≤ k)


Output



k.


Examples



input



2 10 8 9



output



4



input



3 5 4 4 4



output



3


Note



Consider the first example testcase.

10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4marks in total) to the registry, achieving Noora having average mark equal to 

codeforces 810A Straight «A»_codeforces

. Consequently, new final mark is 10. Less number of marks won't fix the situation.

[5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5



题意:有了n个数的和,求再添加几个最大值(k),得到的平均值为k,包含四舍五入。

#include<stdio.h>
#include<math.h>
int main()
{
int n,k,a[110],sum=0;
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
int x=0;
while(1)
{
double w=(double)(sum+x*k)/(n+x);
if(floor(w+0.5)==k)
break;
else
x++;
}
printf("%d\n",x);
return 0;
}





举报

相关推荐

0 条评论