Vanya and Exams

CodeForces - 492C

Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade ai for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write biessays. He can raise the exam grade multiple times.

What is the minimum number of essays that Vanya needs to write to get scholarship?

Input

The first line contains three integers nravg (1 ≤ n ≤ 105, 1 ≤ r ≤ 109, 1 ≤ avg ≤ min(r, 106)) — the number of exams, the maximum grade and the required grade point average, respectively.

Each of the following n lines contains space-separated integers ai and bi (1 ≤ ai ≤ r, 1 ≤ bi ≤ 106).

Output

In the first line print the minimum number of essays.

Examples

Input
5 5 4
5 2
4 7
3 1
3 2
2 5
Output
4
Input
2 5 4
5 2
5 2
Output
0

Note

In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point.

In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.

sol:挺明显的贪心,把便宜的都尽量升级的更高,一定是最优的,做到平均数够了为止

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
ll n,Up,Yaoq;
struct Fens
{
ll a,b;
}Score[N];
inline bool cmp_b(Fens p,Fens q)
{
return p.b<q.b;
}
int main()
{
int i;
ll Sum=,ans=;
R(n); R(Up); R(Yaoq);
for(i=;i<=n;i++)
{
R(Score[i].a); R(Score[i].b);
Sum+=1ll*Score[i].a;
}
sort(Score+,Score+n+,cmp_b);
i=;
while(Sum<1ll*n*Yaoq)
{
ll oo=min(1ll*(Up-Score[++i].a),1ll*(1ll*n*Yaoq-Sum));
Sum+=1ll*oo;
ans+=1ll*oo*Score[i].b;
}
Wl(ans);
return ;
}
/*
input
5 5 4
5 2
4 7
3 1
3 2
2 5
output
4 input
2 5 4
5 2
5 2
output
0
*/

codeforces492C的更多相关文章

随机推荐

  1. logistic回归和最大熵

    回顾发现,李航的<统计学习方法>有些章节还没看完,为了记录,特意再水一文. 0 - logistic分布 如<统计学习方法>书上,设X是连续随机变量,X服从logistic分布 ...

  2. WPF效果(GIS二维篇)

    距离上次发东西已经过去了貌似不知多少天了,突然发现自己懒得总结了.这毛病感觉不好,还得写点东西来充实一下自己,不然这样整天浑浑噩噩的过日子,也太平淡了,不管怎么说,起码得给自己的经历留下点东西吧.闲话 ...

  3. 面试 9:Java 玩转冒泡排序

    面试 9:用 Java 实现冒泡排序 南尘的朋友们,新的一周好,原本打算继续讲链表考点算法的,这里姑且是卡一段.虽然在我们 Android 开发中,很少涉及到排序算法,因为基本官方都帮我们封装好了,但 ...

  4. Python实现将爱词霸每日一句定时推送至微信

    前言 前几天在网上看到一篇文章<教你用微信每天给女票说晚安>,感觉很神奇的样子,随后研究了一下,构思的确是巧妙.好,那就开始动工吧!服务器有了,Python环境有了,IDE打开了...然而 ...

  5. Python监控服务器利器--psutil

    Python监控服务器利器--psutil 服务器的监控通过安装一些常用的监控软件之外,有时也需要运行一些shell或Python脚本:shell下可以使用系统自带的ps/free/top/df等sh ...

  6. 多路选择器实现总线结构——Verilog

    ////////////////////////////////////////////////////////////////////////////////// //该程序完成通过多路选择器MUX ...

  7. T-shirt buying CodeForces - 799B (小根堆+STL)

    题目链接 思路: 由于题目说了只有1,2,3,三种色号的衣服,然后开三个对应色号的小根堆, 我是根据pair<int,int> 创建了一个以价格小的优先的优先队列. pair中的另外一个i ...

  8. PS调出通透唯美阳光外景女生照片

    1.稍微增加了一点曝光度,让照片更明亮. 2.对比度的话我现在比习惯加一点,而且 一般导入PS之后我还会按照片情况去加对比度. 3.高光的部分一般会拉回来一点,根据照片调. 4.阴影部分加一点的话会让 ...

  9. 福州大学软件工程1816 | W班 第1次作业成绩排名

    1.作业地址 第一次作业--准备篇 2.作业要求 (1)回想一下你初入大学时对计算机专业的畅想 当初你是如何做出选择计算机专业的决定的? 你认为过去两年中接触到的课程是否符合你对计算机专业的期待,为什 ...

  10. Jenkins redeploy artifacts

    jenkins redeploy artifacts 按钮 - 开源中国https://www.oschina.net/question/3045293_2247829 Jenkins 构建失败后通过 ...