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的更多相关文章
随机推荐
- python:面向对象编程之Zope.interface安装使用
持续学习python+django中... 一.接口简述 在我们所熟知的面向对象编程语言中,大多提供了接口(interface)的概念.接口在编程语言中指的是一个抽象类型,是抽象方法的集合:它的特点如 ...
- wtf_1234
好无聊啊,今天困的厉害. 不想做任何事情 wtf bitch!
- Spring基于AspectJ的AOP的开发——注解
源码:https://gitee.com/kszsa/dchart 一, AspectJ的概述: AspectJ是一个面向切面的框架,它扩展了Java语言.AspectJ定义了AOP语法所以它有一个专 ...
- 1060D Social Circles(贪心)
题意:有n个客人,第i个客人希望左边至少Li个空椅子,右边至少Ri个空椅子,每个客人都属于一个圈,问你最少需要准备的椅子数量 贪心做,每个人都可以去和另一个人牵手,组成一个新的人,那么我们让大的和大的 ...
- Linux常用软件启动、停止、重启命令
一.PHP 启动命令: /usr/local/php5/sbin/php-fpm 停止命令: pkill php-fpm 二.MySQL 启动命令: /etc/init.d/mysqld start ...
- semantic-ui 下拉框
注意:在使用semantic的下拉框的时候,不仅需要引入semantic.css,还要引入semantic.js,最重要的是引入jquery.否则下拉效果不会显示. 并且,jquery必须先于sema ...
- Handling duplicate form submission in Spring MVC
javaweb开发之防止表单重复提交 - u012843873的博客 - CSDN博客 https://blog.csdn.net/u012843873/article/details/5526212 ...
- CRM系统设计方案
CRM系统设计方案 - 百度文库https://wenku.baidu.com/view/a34eebeb0242a8956bece473.html 服务支持http://www.uf-crm.com ...
- Linux中profile
http://www.cnblogs.com/mmfzmd517528/archive/2012/07/05/2577988.html
- MySQL之慢查询日志和通用查询
MySQL中的日志包括:错误日志.二进制日志.通用查询日志.慢查询日志等等.这里主要介绍下比较常用的两个功能:通用查询日志和慢查询日志. 1.通用查询日志:记录建立的客户端连接和执行的语句. 2.慢查 ...