博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces 810A
阅读量:6589 次
发布时间:2019-06-24

本文共 3404 字,大约阅读时间需要 11 分钟。

A. Straight «A»
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] (4marks 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.

题意:最少添加result个k使得平均值大于等于k-0.5

分析:不太喜欢精度问题,被0.5坑过,因此我二分答案,看添加result个k可以使得abs(sum2-(k-1)*(n+mid))>=abs(sum2-k*(n+mid))即可。也可以暴力过

AC代码:

#include 
using namespace std;int a[105];int main(){ int n,k; long long sum; while(cin>>n>>k){ sum=0; for(int i=0;i
>a[i]; sum=sum+a[i]; } long long result=0; long long low=0,high=0x3f3f3f3f; long long sum2; while(low<=high){ long long mid=(low+high)/2; sum2=sum+mid*k; if(abs(sum2-(k-1)*(n+mid))>=abs(sum2-k*(n+mid))){ result=mid; high=mid-1; } else { low=mid+1; } } cout<
<

  

 

转载于:https://www.cnblogs.com/ls961006/p/6906415.html

你可能感兴趣的文章
最大熵模型
查看>>
【开发问题记录①】关于滑动CollectionView时ContentSize变化的问题
查看>>
JavaScript 中call apply 那点简单事
查看>>
k8s使用glusterfs实现动态持久化存储
查看>>
java中GC的基本概念
查看>>
building xxx gradle project info的解决办法
查看>>
【Leetcode】98. 验证二叉搜索树
查看>>
Vagrant (一) - 基本知识
查看>>
CSS选择器
查看>>
在 CentOS 7 上搭建 Jenkins + Maven + Git 持续集成环境
查看>>
一星期的学习
查看>>
Javascript 闭包详解
查看>>
数据结构与算法 | Leetcode 19. Remove Nth Node From End of List
查看>>
一起来读you don't know javascript(一)
查看>>
[LeetCode] 862. Shortest Subarray with Sum at Least K
查看>>
BIO、伪异步 IO、AIO和NIO
查看>>
【分享】终端命令工具 自动生成vue组件文件以及修改router.js
查看>>
Div层悬浮实现HTML5 Canvas背景动画
查看>>
技术和商业的碰撞,谈阿里云与天猫双11这十年
查看>>
mysql并发replace死锁
查看>>