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

A题给定一个大小为n的数组,求加上多少个k平均值可以四舍五入到k,签到题,我比较怂,敲好了也不敢交,这个题都有人被FST了,奇怪

#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
int s=;
for(int i=;i<n;i++){
int p;
cin>>p;
s+=p;
}
for(int l=;;l++){
if((l*k+s)*1.0/(n+l)+0.5>=k){
printf("%d",l);
break;
}
} 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 kiproducts 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的双元数组,可以把k个第一个数变成2倍,大于第二个值就取第二个值,小于就取第一个值,所以找到最大贡献进行排序就好

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
struct node{
int x,l,shou;
bool friend operator <(node a,node b){
if(a.shou>b.shou)
return ;
return ;}
}AC[N];
int main(){
int n,k;
scanf("%d%d",&n,&k);
for(int i=;i<n;i++){
scanf("%d%d",&AC[i].x,&AC[i].l);
AC[i].shou=min(AC[i].x,AC[i].l-AC[i].x);}
sort(AC,AC+n);
long long s=;
for(int i=;i<k;i++){
AC[i].x*=;
s+=min(AC[i].x,AC[i].l);
}
for(int i=k;i<n;i++){
s+=min(AC[i].x,AC[i].l);
}
printf("%lld",s); return ;
}
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 0and 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.

C题很简单哇,就和我前几天做的那道很像,就是求贡献啊,我拿上次的代码修改了下AC了,但被FST了,尴尬。这个其实更简单啊,直接sort就可以确定其贡献,

单调栈的贡献怎么会对啊,突然尴尬,而且我还做出D

#include <cstdio>
#include <algorithm>
using namespace std;
const int N=,mod=1e9+;
__int64 a[N],C[N];
int main()
{int n;
while(~scanf("%d",&n)){
int s=;
C[]=;
for(int i=;i<=n;i++){
s=s*%mod;
C[i]=s;}
for(int i=;i<=n;i++)
scanf("%I64d",&a[i]);
sort(a+,a+n+);
__int64 sum=;
for(int i=n;i;i--){
sum+=(C[i-]-C[n-i])%mod*a[i];
sum%=mod;
}
if(sum<)sum+=mod;
printf("%I64d\n",sum);}
return ;
}
D. Glad to see you!
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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čkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.

In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.

The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 ≤ x, y ≤ n). After that Noora chooses some dish a for the number xsuch that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value  is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says «TAK» to Leha, if , and «NIE» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.

Help Leha to solve this problem!

Input

There are two numbers n and k (2 ≤ k ≤ n ≤ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.

Output

If you want to provide an answer, output a string of the form 2 x y (1 ≤ x, y ≤ n, x ≠ y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.

Interaction

While helping Leha, you can ask queries to Noora no more than 60 times. Each query should be printed in it's own line and have the form 1 x y (1 ≤ x, y ≤ n). You have to both print the end-of-line character and flush the output. After flushing you should read the answer for this query from input.

After each query jury's program will print one line «TAK» or «NIE» (without quotes) in input stream depending on the girl's answer.

To flush you can use (just after printing an integer and end-of-line):

  • fflush(stdout) in C++;
  • System.out.flush() in Java;
  • stdout.flush() in Python;
  • flush(output) in Pascal;
  • see the documentation for other languages.

Hacking

For hacking you should write numbers n and k (2 ≤ k ≤ n ≤ 105) in the first line and, for describing dishes Noora ordered, k different integers a1, a2, ..., ak (1 ≤ ai ≤ n), written in ascending order in the second line. Of course, solution you want to hack won't be able to read the numbers of ordered dishes.

Example
input
3 2
NIE
TAK
NIE
TAK
TAK
TAK
output
1 1 2
1 2 1
1 1 3
1 3 1
1 2 3
1 3 2
2 2 3
Note

There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value . For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case .

Let Leha asks Noora about the next couple of dishes:

  • x = 1, y = 2, then he'll recieve «NIE» answer, because |1 - 2| > |2 - 2|
  • x = 2, y = 1, then he'll recieve «TAK» answer, because |2 - 2| ≤ |1 - 2|
  • x = 1, y = 3, then he'll recieve «NIE» answer, because |1 - 2| > |3 - 3|
  • x = 3, y = 1, then he'll recieve «TAK» answer, because |3 - 3| ≤ |1 - 2|
  • x = 2, y = 3, then he'll recieve «TAK» answer, because |2 - 2| ≤ |3 - 3|
  • x = 3, y = 2, then he'll recieve «TAK» answer, because |3 - 3| ≤ |2 - 2|

According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.

这个D原来就是二分啊,

给你一个n和k,代表从n个数选了k个,然后通过询问其中两个并输出,你的询问不超过60次。你的询问是x、y,如果存在离x更近的点 返回TAK给你,如果离y近返回NIE

这个算交互的

#include <bits/stdc++.h>
using namespace std;
int n,k;
bool query(int x,int y)
{
if(x<||y>n)
return false;
string re;
cout<<<<" "<<x<<" "<<y<<"\n";
cin>>re;
return re=="TAK";
}
int get(int l,int r)
{
if(l>r)
return -;
while(l<r)
{
int m=(l+r)/;
if(query(m,m+))
r=m;
else
l=m+;
}
return l;
}
int main()
{
scanf("%d%d",&n,&k);
int x,y;
x=get(,n);
y=get(,x-);
if(!query(y,x))
y=get(x+,n);
printf("2 %d %d\n",x,y);
return ;
}

Codeforces Round #415 (Div. 2) 翻车啦的更多相关文章

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

    A. Straight «A» time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

  2. Codeforces Round#500 Div.2 翻车记

    A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...

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

  4. Codeforces Round#509 Div.2翻车记

    A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...

  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. Educational Codeforces Round 56 Div. 2 翻车记

    A:签到. B:仅当只有一种字符时无法构成非回文串. #include<iostream> #include<cstdio> #include<cmath> #in ...

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

  9. Educational Codeforces Round 55 Div. 2 翻车记

    A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...

随机推荐

  1. Todolist总结

    一.组件类里面的函数尽可能写成箭头函数的形式,方便绑定this 上面的箭头函数是好的,写面的不好,他需要在用的时候绑定this,或者在constructor绑定,如下: 如上用的时候绑定this是不好 ...

  2. azure 创建redhat镜像帮助

    为 Azure 准备基于 Red Hat 的虚拟机 从 Hyper-V 管理器准备基于 Red Hat 的虚拟机 先决条件 本部分假定你已经从 Red Hat 网站获取 ISO 文件并将 RHEL 映 ...

  3. JS判断两个对象相同属性的属性值是否相等

    function isObjectValueEqual(a, b) { var aProps = Object.getOwnPropertyNames(a); var bProps = Object. ...

  4. PL/SQL学习笔记(四)之——删除重复记录

    例:假设员工表中有若干记录重复,请删除重复的记录(某企业面试题) ------模拟建表 create table employee( e_id varchar2(20) primary key, e_ ...

  5. nGrinder技术架构图

  6. Flask信号流程

    首先先我们来看看Flask里面的信号是什么样的,我们可以找到一个叫signals.py的文件 这里面是所有定义了的后面请求流程中会用到的信号 二.哪些地方用到了信号 1.请求app上下文时执行的,在执 ...

  7. css3 省略号

    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; 也无需给元素设置固定宽度!

  8. Codeforces Round #317 (Div. 2) D Minimization (贪心+dp)

    D. Minimization time limit per test  2 seconds memory limit per test  256 megabytes input  standard ...

  9. 多源最短路径 – Floyd-Warshall Algorithm

    介绍: 是解决任意两点间的最短路径的一种算法,可以正确处理有向图或负权(但不可存在负权回路)的最短路径问题,同时也被用于计算有向图的传递闭包. Floyd-Warshall算法的时间复杂度是O(N3) ...

  10. 第二次团队作业-PANTHER考勤系统需求分析

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1 这个作业要求在哪里 https://edu.cnblo ...