time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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.

In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 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.

For instance, if Noora has marks [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.

To graduate with «A» certificate, Noora has to have mark k.

Noora got 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

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ k) denoting marks received by Noora before Leha's hack.

Output

Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.

Examples
Input
2 10
8 9
Output
4
Input
3 5
4 4 4
Output
3
Note

Consider the first example testcase.

Maximal mark is 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] (4 marks in total) to the registry, achieving Noora having average mark equal to . Consequently, new final mark is 10. Less number of marks won't fix the situation.

In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.

这个题就是让你算要加几个K,使得总数的平均值四舍五入等于k。

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
int main(){
int a[];
int n,m;
double sum,ave;
while(~scanf("%d",&n)){
scanf("%d",&m);
sum=;
for(int i=;i<n;i++){
scanf("%d",&a[i]);
sum+=a[i]*1.0;
}
ave=sum/n;
if(ave>=(m*1.0-0.5)) printf("0\n");
else{
for(int i=;i<=N;i++){ //这里的N要大一些,我一开始写的i<=n*m,太小了,会wa
sum+=m*1.0;
ave=sum/(n+i);
if(ave>=(m*1.0-0.5)){
printf("%d\n",i);
break;
}
}
}
}
return ;
}

Codeforces 810 A.Straight «A»的更多相关文章

  1. 【codeforces 810A】Straight «A»

    [题目链接]:http://codeforces.com/contest/810/problem/A [题意] 有n门课的成绩,和一个整数k代表每门课的满分都是k分; 然后这n门课的成绩是按照平均分算 ...

  2. codeforces 810 D. Glad to see you!(二分+互动的输入方式)

    题目链接:http://codeforces.com/contest/810/problem/D 题意:两个人玩一场游戏要猜出Noora选的f种菜的任意两种.一个人猜点另一个人回答 TAK如果 ,(x ...

  3. Codeforces 810 C. Do you want a date?

    C. Do you want a date? time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. Codeforces 810 B. Summer sell-off

    B. Summer sell-off   time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. CF 810 D. Glad to see you!

    codeforces 810 D. Glad to see you! http://codeforces.com/contest/810/problem/D 题意 大小为k的集合,元素的范围都在[1, ...

  6. Codeforces 810C Do you want a date?(数学,前缀和)

    C. Do you want a date? time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  7. Codeforces Round #415 (Div. 2)(A,暴力,B,贪心,排序)

    A. Straight «A» time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

  8. Codeforces Round#415 Div.2

    A. Straight «A» 题面 Noora is a student of one famous high school. It's her final year in school - she ...

  9. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

随机推荐

  1. URL大小写敏感之谜

    URL其实就是我们浏览器地址栏的地址,一般由三部分组成: 协议名称,一般就是http 域名,也就是主机名 资源路径 如链接:http://www.w3school.com.cn/js/js_obj_r ...

  2. JVM GC Q&A(补充ing)

    1.如果一个对象没有与其相连的GC ROOT,一定会被回收吗? 这个对象并非是非死不可的,这时他只是处于死缓阶段,要真正宣告一个对象的死亡,至少要经历两次标记过程:如果对象在进行可达性分析后发现并没有 ...

  3. JQuery排错关于$(document).ready(function(){});

    最近写了好多JQuery.也出了很多问题.不知道怎么回事.程序就不往下执行了.很是郁闷. 查了下资料,这里可能会有以下几种原因:1.js文件的引用路径不正确,特别是使用了命名空间,容易造成路径错误,使 ...

  4. 洛谷 P2387 [NOI2014]魔法森林 解题报告

    P2387 [NOI2014]魔法森林 题目描述 为了得到书法大家的真传,小 E 同学下定决心去拜访住在魔法森林中的隐 士.魔法森林可以被看成一个包含 n 个节点 m 条边的无向图,节点标号为 1,2 ...

  5. 【bzoj2756 奇怪的游戏】

    Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 4403  Solved: 1226[Submit][Status][Discuss] Descript ...

  6. jQuery.getJSON跨域访问的正确使用方式(史上最傻瓜式解释)

    最近花了2天时间完整的看了一遍 jQuery 的API,其中 $.getJSON(url[, data][, callback]) 方法的跨域访问解释真心看的一头雾水,大家可以从这里感受一下: htt ...

  7. git clone 出错 fatal: pack has bad object at offset 26060927: inflate returned -3

    $ git clone http://xxx.xxx.cn/liyafei/developer.gitCloning into 'developer'...remote: Counting objec ...

  8. SCOI2010 传送带 [三分/模拟退火]

    题目描述 在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R.现在lxh ...

  9. [lucene系列笔记2]在eclipse里初步使用lucene的索引和查询功能

    首先,new一个java project,名字叫做LuceneTools. 然后,在project里new一个class,名字叫做IndexFiles.这个类用来给文件建索引(建好索引以后就可以高效检 ...

  10. HDU4725:The Shortest Path in Nya Graph(最短路)

    The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...