Codeforces Round #415(Div. 2)-810A.。。。 810B.。。。 810C.。。。不会
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 Round #415(Div. 2)-810A.。。。 810B.。。。 810C.。。。不会的更多相关文章
- 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 Round #415 Div. 1
		
A:考虑每对最大值最小值的贡献即可. #include<iostream> #include<cstdio> #include<cmath> #include< ...
 - Codeforces Round #415 (Div. 2)C
		
反正又是一个半小时没做出来... 先排序,然后求和,第i个和第j个,f(a)=a[j]-a[i]=a[i]*(2^(j-i-1))因为从j到i之间有j-i-1个数(存在或者不存在有两种情况) 又有a[ ...
 - Codeforces Round #415 (Div. 2) A B C 暴力 sort 规律
		
A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
 - Codeforces Round #415 (Div. 2) C. Do you want a date?
		
C. Do you want a date? 2 seconds 256 megabytes Leha decided to move to a quiet town Vičkopolis, ...
 - Codeforces Round #415 (Div. 2) B. Summer sell-off
		
B. Summer sell-off time limit per test 1 second memory limit per test 256 megabytes Summer hol ...
 - Codeforces Round #415 (Div. 2)  翻车啦
		
A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
 - Codeforces Round #415 (Div. 1) (CDE)
		
1. CF 809C Find a car 大意: 给定一个$1e9\times 1e9$的矩阵$a$, $a_{i,j}$为它正上方和正左方未出现过的最小数, 每个询问求一个矩形内的和. 可以发现$ ...
 
随机推荐
- iOS 环信透传cmd消息多次重复接收,解决办法
			
由于项目需求,需要在项目中接到消息的时候做不同界面的不同的操作,哪儿需要哪儿就要添加代理:引起代理事件重复执行:所以要在VC显示的时候添加代理,消失的时候删除代理 环信 透传 消息多次接收情况(由于代 ...
 - 百度云BCC配置Apache VirtualHost 实现相同域名不同端口访问不同应用
			
问题描述:前戏:本人在百度云上购买了BCC虚拟服务,并购买域名,部署应用,可以正常访问(这里一切都很正常^_^). 事情正在起变化:随着开发的不断推进,工程在本地测试成功后,部署到服务器,会发现有些页 ...
 - Java并发编程之ThreadLocal源码分析
			
## 1 一句话概括ThreadLocal<font face="微软雅黑" size=4> 什么是ThreadLocal?顾名思义:线程本地变量,它为每个使用该对象 ...
 - 后缀数组之hihocoder 重复旋律1-4
			
蒟蒻知道今天才会打后缀数组,而且还是nlogn^2的...但基本上还是跑得过的: 重复旋律1: 二分答案,把height划分集合,height<mid就重新划分,这样保证了每个集合中的LCP&g ...
 - js功能代码大全
			
1.日期格式化 //化为2017-08-14 function formatDate (date) { var y = date.getFullYear(); var m = date.getMont ...
 - asp.net core 2.0+sqlsugar搭建个人网站系列(0)
			
一些废话 马上就要过年了,回顾这一年最大的收获就是技术有了很大的提升,其他的方面没有什么改变,现在还是单身小屌丝一枚. 这一年来学习的主要重点就是asp.net core,中间也使用 core+EF做 ...
 - Eclipse配置tomcat程序发布到哪里去了?
			
今天帮同事调一个问题,明明可以main函数执行的,他非要固执的使用tomcat执行,依他.但是发布到tomcat之后我想去看看发布后的目录,所以就打开了tomcat中的webapps目录,可是并没有发 ...
 - css中使用if条件在各大浏览器(IE6\IE7\IE8)中hack方法解决教程
			
一个滚动代码,其他浏览器都滚的好好的,就IE出现错误,DIV+CSS if条件hack,这里DIVCSS5为大家介绍针对各大浏览器(IE6\IE7\IE8)中使用if条件hack方法教程,DIV CS ...
 - 如何高逼格读取Web.config中的AppSettings
			
http://edi.wang/post/2015/4/22/how-to-read-webconfig-appsettings-with-bigiblity 先插句题外话,下版本的ASP.NET貌似 ...
 - LNMP架构之搭建wordpress博客网站
			
系统环境版本 [root@db02 ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@db02 ~]# uname -a Lin ...