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] (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.

题目链接:http://codeforces.com/contest/810/problem/A

分析:此题只要注意精度就行,题意没有困难的地方,我就不解释了,看代码吧(如果有问题Q我吧)

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k,m;
while(scanf("%d%d",&n,&k)!=EOF)
{
int sum=;
for(int i=;i<=n;i++)
{
scanf("%d",&m);
sum+=m;
}
int ans=;
while()
{
if((double)sum/(ans+n)>=(double)k-0.5)
{
cout<<ans<<endl;
break;
}
sum+=k;
ans++;
}
}
return ;
}

B. Summer sell-off

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.

Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.

For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out.

Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem.

Input

The first line contains two integers n and f (1 ≤ n ≤ 105, 0 ≤ f ≤ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.

Each line of the following n subsequent lines contains two integers ki, li (0 ≤ ki, li ≤ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day.

Output

Print a single integer denoting the maximal number of products that shop can sell.

Examples
Input
4 2
2 1
3 5
2 3
1 5
Output
10
Input
4 1
0 2
0 3
3 5
0 6
Output
5
Note

In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.

In the second example it is possible to sell 5 products, if you choose third day for sell-out.

题目链接:http://codeforces.com/contest/810/problem/B

题意:每天有ki件物品,你知道每天能卖掉li件; 然后让你选f天; 这f天,可以将ki乘上2;
每天结束之后物品清空; 问你最多能卖多少件物品;

分析:先算出来不用f天的乘2效果; 卖出的物品数目;
然后考虑; 乘2之后,能够多卖的物品数量; 排个序,逆序排,然后取前f个就好; 累加答案;

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=;
struct Node
{
ll sum,cnt,ans;
}p[N];
bool cmp(Node a,Node b)
{
return a.ans>b.ans;
}
int main()
{
ll n,f;
while(scanf("%lld%lld",&n,&f)!=EOF)
{
for(ll i=;i<=n;i++)
scanf("%lld%lld",&p[i].sum,&p[i].cnt);
ll res=;
for(ll i=;i<=n;i++)
res+=min(p[i].sum,p[i].cnt);
for(ll i=;i<=n;i++)
{
if(p[i].sum<=p[i].cnt)
{
p[i].cnt-=p[i].sum;
p[i].ans=min(p[i].cnt,p[i].sum);
}
else
p[i].ans=;
}
sort(p+,p++n,cmp);
for(ll i=;i<=f;i++)
res+=p[i].ans;
cout<<res<<endl;
}
return ;
}

最新文章

  1. BZOJ3197 &amp; 组合乱搞
  2. 解决maven创建web项目卡死在generator插件(转)
  3. 转载--How to Install VMware Tools on CentOS 6.3
  4. Linux下的IO模式
  5. H5案例分享:html5重力感应事件
  6. 【超详细教程】使用Windows Live Writer 2012和Office Word 2013 发布
  7. C++Primer 第十六章
  8. dedecms:织梦文章如何添加“自定义属性”标签(sql命令行工具)
  9. 代码研磨 Slim v3 (二)--app-&gt;run()
  10. WPF学习笔记 控件篇 属性整理【1】FrameworkElement
  11. HTML5与CSS3权威指南.pdf2
  12. 安装vs2013 Sqlserver 无法连接远程服务器的解决方法
  13. Spiral Matrix 解答
  14. 搜狐畅游:每月给员工直系长辈2000元爱孝薪_企业新闻_265G产业频道
  15. java线程并发控制:ReentrantLock Condition使用详解
  16. Cookie和Session总结
  17. 利用Qt Designer 进行 空间提升propomotion 的时候异常: NO such file or directory
  18. iOS项目之获取WebView的高度
  19. linux 服务发布脚本升级,远程发布,指定拉取远程dev,test等分支代码
  20. Java内存管理之类似-Xms、-Xmx 这些参数的含义

热门文章

  1. MongoDB入门系列(二):Insert、Update、Delete、Drop
  2. nodejs+mongodb+vue前后台配置ueditor
  3. magento获取商品的图片
  4. 设计模式之 - 模板模式(Template Pattern)
  5. 海外ubuntu,lamp,ftp,phpmyadmin配置
  6. MySQL5.6中date和string的转换和比较
  7. Hello TensorFlow 三 (Golang)
  8. windows server数据库备份
  9. ubuntu12.04 安装中文输入法
  10. 表单Checkbox全选反选全不选