codeforces——810A——Straight «A»
来源:互联网 发布:电脑打字用什么软件 编辑:程序博客网 时间:2024/06/06 09:26
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 from1 to k. The worst mark is1, 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 — to8.
For instance, if Noora has marks [8, 9], then the mark to the certificate is9, 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 markk.
Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final markk. 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 from1 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 andk (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 tok.
2 108 9
4
3 54 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 is10. 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 to4.5, which is enough to have 5 in the certificate.
输入n,m,输入n个数,求加多少个m后,平均数四舍五入可以达到m的值。
水题。
#include<iostream>#include<algorithm>#include<stdio.h>#include<cstring>#include<cmath>#include<map>using namespace std;int main(){ int n,m; while(cin>>n>>m!=NULL) { int N=n,sum=0,ans=0; double fin=m-0.5; while(N--) { int t=0; cin>>t; sum+=t; } if(sum/(n*1.0)>=fin) { cout<<ans<<endl; continue; } while(sum/(n*1.0)<fin) { sum+=m; n++; ans++; } cout<<ans<<endl; } return 0;}
- codeforces——810A——Straight «A»
- CodeForces 810A——Straight «A» ——二分
- codeforces 810A Straight «A»
- 【Codeforces 808 A. Straight «A»】
- Codeforces 810A Straight «A» 题解
- CodeFroces 810A Straight «A»
- 810A. Straight «A»
- Codeforces Round #415 (Div. 2) A. Straight «A»
- Codeforces Round #415 (Div. 2) A. Straight «A»
- CodeForces 810A Straight <<A>> 【数学】【模拟】
- codeforces 810A Straight <<A>> 暴力
- A. Straight «A»
- Codeforces Round #415 (Div. 2)A. Straight «A» (暴力)
- Codeforces Round #415 A Straight <<A>>
- 0526 CF#801A&G2n#D-Straight «A»
- codeforces——732A——Buy a Shovel
- 【codeforces #3】A——BFS+贪心
- Codeforces —— 359A Table
- yarn安装与测试
- 5月29日
- Q-学习:增强学习
- 函数类型
- selenium元素选择
- codeforces——810A——Straight «A»
- 搭建简单的nginx
- 再议C#委托
- Chapter4.1.1 函数的对象
- 简单的登录、注册以及带有验证码功能
- selenium动作
- hibernate-核心开发接口-6
- CSU-1945 最简单的题目
- hadoop、hbase、hive版本兼容信息