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. Android/Linux boot time分析优化

    如果需要优化boot time,就需要一个量化的工具来分析每个阶段的时间消耗.这种类型的优化特别适合使用基于timeline的图表,有着明显的时间顺序.要求不但能给出整个流程消耗的时间,还要能对流程进 ...

  2. 欢迎加入.NET Core 技术QQ群一起讨论交流学习

    群号:4656606 介绍:本群主要讨论.NET Core及其相关技术,如:IdentityServer4.ABP.Dcoker.Linux.Devops.微服务等,如果你正在使用或者准备使用.NET ...

  3. 如何选择分布式事务形态(TCC,SAGA,2PC,补偿,基于消息最终一致性等等)

    各种形态的分布式事务 分布式事务有多种主流形态,包括: 基于消息实现的分布式事务 基于补偿实现的分布式事务(gts/fescar自动补偿的形式) 基于TCC实现的分布式事务 基于SAGA实现的分布式事 ...

  4. sql面试学到新内容

    1.事物的保存点 MYSQL可以让我们对事务进行部分回滚,就是在事务里调用SAVEPOINT语句来设置一些命名标记.如果想要回滚到那个标记点位置,需要使用ROLLBACK语句来指定哪个保存点. mys ...

  5. 埋锅。。。BZOJ1004-置换群+burnside定理+

    看这道题时当时觉得懵逼...这玩意完全看不懂啊...什么burnside...难受... 于是去看了点视频和资料,大概懂了置换群和burnside定理,亦步亦趋的懂了别人的代码,然后慢慢的打了出来.. ...

  6. Java开学测试源代码

    package sample; import java.io.IOException;import java.io.Serializable;import java.util.Scanner;impo ...

  7. c++入门之再次探讨类属性

    精辟博文:https://blog.csdn.net/msdnwolaile/article/details/51923859(转载,仅供学习|!)

  8. redis的应用场景 为什么用redis

    一.不是万能的菲关系系数据库redis 在面试的时候,常被问比较下Redis与Memcache的优缺点,个人觉得这二者并不适合一起比较,redis:是非关系型数据库不仅可以做缓存还能干其它事情,Mem ...

  9. ElasticSearch Nosql

    把 ElasticSearch 当成是 NoSQL 数据库 Elasticsearch 可以被当成一个 "NoSQL"-数据库来使用么? NoSQL 意味着在不同的环境下存在不同的 ...

  10. [已解决]关于python无法显示中文的问题:SyntaxError: Non-ASCII character '\xe4' in file test.py on line 3, but no encoding declared。

    想在python代码中输出汉字.但是老是出现SyntaxError: Non-ASCII character '\xe4' in file test.py on line , but no encod ...