CodeForce 492C(贪心)
来源:互联网 发布:淘宝联盟高佣活动在哪 编辑:程序博客网 时间:2024/05/29 04:07
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 bi essays. 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.
Sample Input
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
Hint
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.
很典型的贪心,根据bi排个序,在选择,水题。
#include<cstdio>#include<algorithm>using namespace std;typedef struct Project{ int a; int b;}PROJECT;PROJECT project[100010];int cmp(PROJECT m,PROJECT n){ return m.b<n.b;}int main(){ long long n,r,avg; while(~scanf("%I64d %I64d %I64d",&n,&r,&avg)) { long long sumavg=avg*n,sum=0; for(int i=0;i<n;i++) { scanf("%d %d",&project[i].a,&project[i].b); sum+=project[i].a; } if(sum>=sumavg) { printf("0\n"); break; } long long ans=0; sort(project,project+n,cmp); for(int i=0;i<n&&sum<sumavg;i++) { long long t=min(sumavg-sum,r-project[i].a); sum+=t; ans+=t*project[i].b; } printf("%I64d\n",ans); } return 0;}
- CodeForce 492C(贪心)
- Codeforce Round #438 C.Bus(贪心)
- CodeForce 463C Gargari and Bishops(贪心+暴力)
- CodeForce 508C Anya and Ghosts (贪心+模拟)
- CodeForce 538C Tourist's Notes(贪心 + 数学)
- codeforce 551C GukiZ hates Boxes(二分+贪心)
- codeforce Round #379 (Div. 2)C(贪心)
- codeforce 492 C D
- CodeForce 3B Lorry(贪心)
- codeforce 3B. Lorry(贪心)
- codeforce 732e Sockets (贪心)
- codeforce-305A--Strange Addition (贪心)
- codeforce 509C (很有趣的贪心模拟构造)
- Codeforce#379C. Anton and Making Potions(二分or贪心)
- codeforce 731C Socks(并查集+贪心)
- [codeforce ] Vacations [贪心]
- codeforce 719b 贪心
- Codeforce 798D(贪心)
- python操作日期和时间的方法
- struts2学习笔记之六(Action访问servlet的API以及复制项目小技巧)
- 编译器手工开栈
- hdu 1081 To The Max(最大连续子序列推广到二维)
- php CURL两个基本实例
- CodeForce 492C(贪心)
- 用户体验测试方法
- 数据结构的堆栈、内存中的堆栈
- Ceph集群磁盘没有剩余空间的解决方法
- mongodb里日期类型的时区问题
- Windows下写用于python的C扩展模块
- 使用Mantle处理Model层对象
- 使用其他资源
- 访问修饰符