您的位置:首页 > 其它

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

2017-05-22 20:29 567 查看
CodeForces - 810A

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.

这个题就是让你算要加几个K,使得总数的平均值四舍五入等于k。

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
int main(){
int a[100];
int n,m;
double sum,ave;
while(~scanf("%d",&n)){
scanf("%d",&m);
sum=0;
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
sum+=a[i]*1.0;
}
ave=sum/n;
if(ave>=(m*1.0-0.5)) printf("0\n");
else{
for(int i=1;i<=N;i++){    //这里的N要大一些,我一开始写的i<=n*m,太小了,会wa
sum+=m*1.0;
ave=sum/(n+i);
if(ave>=(m*1.0-0.5)){
printf("%d\n",i);
break;
}
}
}
}
return 0;
}


下一题

CodeForces - 810B

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.

这个题就是n天里面找f天让商品数量*2使得最终卖出最多的东西。

举个栗子:

4 2

2 1
3 5
2 3
1 5

4天里面选2天

第一竖行是商品数量,第二竖行是顾客数量(不用管题目中的保质期(英语不好,被这个保质期搞得有点傻(/ω\)))

第一个数据,2个商品,1个顾客,不管*2还是不*2,商品数量都比顾客数量多,没用

第二个数据,3个商品,5个顾客,3<5,*2之后是6个商品,最后卖出去5个(因为就5个顾客)

。。。都是这个意思

所以,

就先把没*2的时候可以卖出去的数量先存到一个数组里,然后求和sum。

然后再每一个数据都*2,把还可以继续卖出去的数量存到另一个数组里,然后排排坐,大的在前面,小的在后面(保证是卖出去最多的)

之后按照要求,因为是其中f天的商品数量*2,所以把排好序的另一个数组里的前f个加到sum里,就可以了

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
struct node{
int ss;
int cc;
}a
;
bool cmp(int a,int b){
return a>b;
}
int main(){
int b
,c
;
int n,m;
ll sum;
while(~scanf("%d%d",&n,&m)){
for(int i=0;i<n;i++)
scanf("%d%d",&a[i].ss,&a[i].cc);
for(int i=0;i<n;i++){
if(a[i].ss>=a[i].cc){
b[i]=a[i].cc;
c[i]=0;
}
else if((a[i].cc>a[i].ss)&&(2*a[i].ss>a[i].cc)){    //这里一开始写错了2*a[i].ss>a[i].cc写成<了
b[i]=a[i].ss;
c[i]=a[i].cc-a[i].ss;
}
else if(2*a[i].ss<=a[i].cc){
b[i]=a[i].ss;
c[i]=a[i].ss;
}
}
sort(c,c+n,cmp);
sum=0;
for(int i=0;i<n;i++)
sum+=b[i];
for(int i=0;i<m;i++)
sum+=c[i];
printf("%lld\n",sum);
}
return 0;
}


下一题

CodeForces - 810C

C. Do you want a date?

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

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 get access to n computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis.

Let's denote the coordinate system on this street. Besides let's number all the hacked computers with integers from 1 to n. So the i-th hacked computer is located at the point xi. Moreover the coordinates of all computers are distinct.

Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task.

Leha should calculate a sum of F(a) for all a, where a is a non-empty subset of the set, that consists of all hacked computers. Formally, let's denote A the set of all integers from 1 to n. Noora asks the hacker to find value of the expression

. Here F(a) is calculated as the maximum among the distances between all pairs of computers from the set a. Formally,

. Since the required sum can be quite large Noora asks to find it modulo 109 + 7.

Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date.

Input
The first line contains one integer n (1 ≤ n ≤ 3·105) denoting the number of hacked computers.

The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 109) denoting the coordinates of hacked computers. It is guaranteed that all xi are distinct.

Output
Print a single integer — the required sum modulo 109 + 7.

Examples

Input
2
4 7


Output
3


Input
3
4 3 1


Output
9


Note
There are three non-empty subsets in the first sample test:

,

and

. The first and the second subset increase the sum by 0 and the third subset increases the sum by 7 - 4 = 3. In total the answer is 0 + 0 + 3 = 3.

There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer:

,

,

,

. In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.

说实话,这个题还不太懂意思

代码:

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int N=7*1e6+10;
typedef long long ll;
ll a
,b
;
void gg(){
b[0]=1;
for(int i=1;i<=N;i++)
b[i]=(b[i-1]*2)%mod;
}
int main(){
gg();
int n,i;
ll ans;                        //要用long long,不然会wa的
while(~scanf("%d",&n)){
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+1+n);
ans=0;
for(int i=0;i<=n;i++){
ans=(ans-a[i]*(b[n-i]-1)%mod+mod)%mod;
ans=(ans+a[i]*(b[i-1]-1)%mod)%mod;
}
printf("%lld\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: