Codeforces 810 A.Straight «A»
1 second
256 megabytes
standard input
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.
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.
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.
2 10
8 9
4
3 5
4 4 4
3
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»的更多相关文章
- 【codeforces 810A】Straight «A»
[题目链接]:http://codeforces.com/contest/810/problem/A [题意] 有n门课的成绩,和一个整数k代表每门课的满分都是k分; 然后这n门课的成绩是按照平均分算 ...
- codeforces 810 D. Glad to see you!(二分+互动的输入方式)
题目链接:http://codeforces.com/contest/810/problem/D 题意:两个人玩一场游戏要猜出Noora选的f种菜的任意两种.一个人猜点另一个人回答 TAK如果 ,(x ...
- 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 ...
- Codeforces 810 B. Summer sell-off
B. Summer sell-off time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CF 810 D. Glad to see you!
codeforces 810 D. Glad to see you! http://codeforces.com/contest/810/problem/D 题意 大小为k的集合,元素的范围都在[1, ...
- 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 ...
- 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 ...
- 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 ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
随机推荐
- 【SVN】SVN服务器的本地搭建和使用
Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. 首先来下载和搭建SVN服务器. 现在Subversion已经迁移到apache网站上了,下载地址: http:// ...
- IE6,7,8支持css圆角
我们知道Webkit内核的浏览器支持-webkit-border-radius: 10px;属性(10px是圆角半径),可以直接解析出圆角;Firefox浏览器支持-moz-border-radius ...
- 在C/C++函数中使用可变参数
原文链接地址:http://blog.csdn.net/djinglan/article/details/8425768 下面介绍在C/C++里面使用的可变参数函数. 先说明可变参数是什么,先回顾一下 ...
- Educational Codeforces Round 11 A
A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Covered Points Count(思维题)
C. Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- Hbase写入量大导致region过大无法split问题
最近在线上往hbase导数据,因为hbase写入能力比较强,没有太在意写的问题.让业务方进行历史数据的导入操作,中间发现一个问题,写入速度太快,并且业务数据集中到其中一个region,这个region ...
- source改变当前路径
转摘自:http://hi.baidu.com/homappy/item/90e416525d2faf958c12edb7 Shell 脚本执行有三种方法 bash 脚本名 sh 脚本名 chmod ...
- C++中的垃圾回收和内存管理
最开始的时候看到了许式伟的内存管理变革系列,看到性能测试结果的时候,觉得这个实现很不错,没有深入研究其实现.现在想把这个用到自己的一个项目中来,在linux下编译存在一些问题,所以打算深入研究一下. ...
- 51nod 1076 2条不相交的路径
给出一个无向图G的顶点V和边E.进行Q次查询,查询从G的某个顶点V[s]到另一个顶点V[t],是否存在2条不相交的路径.(两条路径不经过相同的边) (注,无向图中不存在重边,也就是说确定起点和终点 ...
- JSP页面中格式化日期为指顶格式
有时候在页面中显示直接从数据库获取的日期时候会出现英文的日期格式.比如: