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 ;
}

Codeforces Round #415 (Div. 2)(A,暴力,B,贪心,排序)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #253 (Div. 2)B(暴力枚举)

    就暴力枚举所有起点和终点就行了. 我做这题时想的太多了,最简单的暴力枚举起始点却没想到...应该先想最简单的方法,层层深入. #include<iostream> #include< ...

  4. Codeforces Round #415 (Div. 1) (CDE)

    1. CF 809C Find a car 大意: 给定一个$1e9\times 1e9$的矩阵$a$, $a_{i,j}$为它正上方和正左方未出现过的最小数, 每个询问求一个矩形内的和. 可以发现$ ...

  5. Codeforces Round #415(Div. 2)-810A.。。。 810B.。。。 810C.。。。不会

    CodeForces - 810A A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes i ...

  6. Codeforces Round #415 Div. 1

    A:考虑每对最大值最小值的贡献即可. #include<iostream> #include<cstdio> #include<cmath> #include< ...

  7. 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[ ...

  8. Codeforces Round #336 (Div. 2)B 暴力 C dp D 区间dp

    B. Hamming Distance Sum time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  9. 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, ...

随机推荐

  1. iOS动态性 运行时runtime初探(强制获取并修改私有变量,强制增加及修改私有方法等)

    借助前辈的力量综合一下资料. OC是运行时语言,只有在程序运行时,才会去确定对象的类型,并调用类与对象相应的方法.利用runtime机制让我们可以在程序运行时动态修改类.对象中的所有属性.方法,就算是 ...

  2. html统计

    <!doctype html><html lang="en"> <head>  <meta charset="UTF-8&quo ...

  3. git push的用法

    git push <远程仓库名> <本地分支名>:<远程分支名>

  4. locust 参数,数据详解

    参数    说明-h, –help    查看帮助-H HOST, –host=HOST    指定被测试的主机,采用以格式:http://10.21.32.33–web-host=WEB_HOST  ...

  5. jamup与gb2i组合

    软件一定要开嗓单效果器,最好不要关闭中断软件/声音,每次有重新检测电流必须会有嗓音,最好用ipad ,不然会烦死人.默认delay太长,在DLY面板修改 gb2i 效果还行,他的价值重在使用,让新人使 ...

  6. Webpack 2 视频教程 014 - 深入理解 Webpack 2 中的 loader

    原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲 ...

  7. what is cdecl?

    cdecl这是一个Linux上功能很强大的一个小型程序,它最主要的功能就是能帮助我们解释一个很复杂的C语言声明. 例如,我写了这样一个C语言的一个声明:int   *(*g[])(int , floa ...

  8. C# 控件拖动

    https://zhidao.baidu.com/question/2116834779399609987.html [DllImport("user32.dll", EntryP ...

  9. NPOI 1.2.5 教程

    NPOI1.2.5教程官方地址 作者:Tony Qu & atao.xiang QQ群:20144214 ===== 持续更新中 ===== a. NPOI简介 b. 版权声明 目录 1. O ...

  10. php isset和empty方法的区别

    我总结了下面几点区别,直接上代码: empty方法: 变量不存在,返回true 变量存在,值为空,返回true 变量存在,值不为空,返回false function empty1(){ //变量不存在 ...