codeforces492C
Vanya and Exams
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 n, r, avg (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
5 5 4
5 2
4 7
3 1
3 2
2 5
4
2 5 4
5 2
5 2
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的更多相关文章
随机推荐
- redis学习(一)——redis介绍及安装
一.redis简介 redis是一个高性能的key-value非关系数据库,它可以存键(key)与5种不同类型的值(value)之间的映射(mapping),支持存储的value类型包括:String ...
- Mysql数据库表被锁定处理
1.查进程,查找被锁表的那个进程的ID show processlist; command 为waitting的就是锁住的表,info为执行某条语句的信息,id为进程. 2.kill掉锁表的进程ID ...
- UI 前端参考
:http://amazeui.org/ :http://www.dcloud.io/index.html :https://weui.io/ :http://m.sui.taobao.org/get ...
- 深入浅出Tomcat/3 - Tomcat生命周期
在上面的部分,其实我们已经接触到Tomcat的生命周期了,接下来我们将仔细讨论和学习Tomcat的生命周期的具体实现. LifeCycle接口 这个LifeCycle接口上面在讲解Server和Ser ...
- @Vue/Cli 3 Invalid Host header 检测关闭
Invalid Host header 在本地开发等一般情况下,无论是 local,还是 ip,或者是 0.0.0.0,在 cli 中都默认为合法的,但是有些场景可能会被不支持,比如远程开发,或者是云 ...
- 小菜鸡儿的第三次OO博客
规格化设计历史 规格化设计的历史目前网上的资料并不多,百度谷歌必应也表示无能为力...... 在这里结合现实情况讲一讲自己对程序规格化的理解,首先代码规格化对代码的影响是间接的,或许它不能让你代码里面 ...
- Python-待
内置函数总结 https://www.cnblogs.com/jason-lv/p/8243141.html https://www.cnblogs.com/pyyu/p/6702896.html 数 ...
- Summer sell-off CodeForces - 810B (排序后贪心)
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying ...
- SDK安装详解以及adb的来源
首先,下载Android SDK Tools,翻过墙的朋友可以去Google Android的官网上下载(http://developer.android.com/sdk/index.html) 选择 ...
- 福州大学软件工程1816 | W班 第10次作业[软件工程实践总结]
作业链接 个人作业--软件工程实践总结 评分细则 本次由五个问题(每个十分)+创意照片(五分)+附加题(十分)组成 评分统计图 千帆竞发图 汇总成绩排名链接 汇总链接