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

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 108 9

Output

4

Input

3 54 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代码:

 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

4 22 13 52 31 5

Output

10

Input

4 10 20 33 50 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代码:

 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 }
时间: 2024-10-14 00:08:29

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

Codeforces Round #224 (Div. 2) D 暴力搜索加记忆化

题意读了半年,英语太渣,题意是摆两个棋子在棋盘上作为起点,但是起点不能在#上,然后按照图的指示开始走, < 左 > 右 ^上 v下,走的时候只能按照图的指示走,如果前方是 #的话,可以走进去,但是 走进去之后便不能再走了,走的途中两个棋子不能相碰,但是最终都走到同一个#里是没事的,并且若是能走 无限步的话 输出 -1, 例如  > < 这样左右左右的走就能无限走,然后问你 两个棋子走的最大步数的和 一开始被输出-1给困住了,因为除了 .> <这样以外  还可以刚好形成一

Codeforces Round #415 (Div. 2)

Straight <<A>> 暴力模拟一下. #include <iostream> #include <algorithm> #include <cmath> using namespace std; int main() { int n,k; cin>>n>>k; double sum = 0; for(int i=0;i<n;i++) { int x; cin>>x; sum += x; } dou

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

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

Codeforces Round #415 (Div. 2) B. Summer sell-off(贪心+结构体排序)

题目链接:http://codeforces.com/contest/810/problem/B 题意:给定天数和货物可以翻倍的天数,每天都有一定的货物量和顾客数,问怎么样货物才能卖得最多(前一天的货物不会留到下一天,每个顾客只能买一个货物). 简单的贪心问题,贪心策略是:如果两倍的货物量卖出去的更多,就选两倍的,否则就选一倍的. 那一天能卖出去的货物量:min(货物量,顾客数).然后根据结构体排序一下就ok了 1 #include <iostream> 2 #include <algo

Codeforces Round #258 (Div. 2)C(暴力枚举)

就枚举四种情况,哪种能行就是yes了.很简单,关键是写法,我写的又丑又长...看了zhanyl的写法顿时心生敬佩.写的干净利落,简直美如画...这是功力的体现! 以下是zhanyl的写法,转载在此以供学习: #include <vector> #include <list> #include <queue> #include <map> #include <set> #include <deque> #include <stac

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, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to

(二分)Codeforces Round #415 (Div. 2) D-Glad to see you!

This is an interactive problem. In the output section below you will see the information about flushing the output. On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in Vi?ko

Codeforces Round #312 (Div. 2)——C暴力技巧——Amr and Chemistry

Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of ai liters. For this experiment, Amr has to mix all the chemicals

Codeforces Round #363 (Div. 2) B 暴力

Description You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x