前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Codeforces Round #415 (Div. 2)(A,暴力,B,贪心,排序)

Codeforces Round #415 (Div. 2)(A,暴力,B,贪心,排序)

作者头像
Angel_Kitty
发布2018-04-09 11:02:02
7120
发布2018-04-09 11:02:02
举报

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

代码语言:javascript
复制
2 10
8 9

Output

代码语言:javascript
复制
4

Input

代码语言:javascript
复制
3 5
4 4 4

Output

代码语言:javascript
复制
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代码:

代码语言:javascript
复制
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int n,k,m;
 6     while(scanf("%d%d",&n,&k)!=EOF)
 7     {
 8         int sum=0;
 9         for(int i=1;i<=n;i++)
10         {
11             scanf("%d",&m);
12             sum+=m;
13         }
14         int ans=0;
15         while(1)
16         {
17             if((double)sum/(ans+n)>=(double)k-0.5)
18             {
19                 cout<<ans<<endl;
20                 break;
21             }
22             sum+=k;
23             ans++;
24         }
25     }
26     return 0;
27 }

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

代码语言:javascript
复制
4 2
2 1
3 5
2 3
1 5

Output

代码语言:javascript
复制
10

Input

代码语言:javascript
复制
4 1
0 2
0 3
3 5
0 6

Output

代码语言:javascript
复制
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代码:

代码语言:javascript
复制
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const ll N=100010;
 5 struct Node
 6 {
 7     ll sum,cnt,ans;
 8 }p[N];
 9 bool cmp(Node a,Node b)
10 {
11     return a.ans>b.ans;
12 }
13 int main()
14 {
15     ll n,f;
16     while(scanf("%lld%lld",&n,&f)!=EOF)
17     {
18         for(ll i=1;i<=n;i++)
19             scanf("%lld%lld",&p[i].sum,&p[i].cnt);
20         ll res=0;
21         for(ll i=1;i<=n;i++)
22             res+=min(p[i].sum,p[i].cnt);
23         for(ll i=1;i<=n;i++)
24         {
25             if(p[i].sum<=p[i].cnt)
26             {
27                 p[i].cnt-=p[i].sum;
28                 p[i].ans=min(p[i].cnt,p[i].sum);
29             }
30             else
31                 p[i].ans=0;
32         }
33         sort(p+1,p+1+n,cmp);
34         for(ll i=1;i<=f;i++)
35             res+=p[i].ans;
36         cout<<res<<endl;
37     }
38     return 0;
39 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-05-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • A. Straight «A»
  • B. Summer sell-off
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档