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的更多相关文章
随机推荐
- ExFilePicker的使用 — 获取本地图片资源并用RecyclerView展示出来
代码其实很简单,所以就不多进行文字说明,直接上完整的代码: 第一步:在app/build.gradle添加需要使用到的依赖库:(这里对引用的版本冲突问题作了处理,详情请看链接:https://www. ...
- WCF无.SVC文件服务激活,及不添加服务引用调用WCF
一,新建WCF服务引用程序 1,删除.svc文件,全部删除. 2,新建 IService 类 namespace TestWcf { [ServiceContract] public interfac ...
- 几种事务的隔离级别,InnoDB如何实现?
事务ACID特性,其中I代表隔离性(Isolation). 什么是事务的隔离性? 隔离性是指,多个用户的并发事务访问同一个数据库时,一个用户的事务不应该被其他用户的事务干扰,多个并发事务之间要相互隔离 ...
- CISCO交换机-SNMP配置
1.1 SNMP基础配置 router> enable 进入路由器是用户模式 router# conf terminal 进入路由器的全局配置模式 #snmp-server commun ...
- Acceleration for ML 论文导读
Energy efficient parallel neuromorphic architectures with approximate arithmetic on FPGA Motivation ...
- 为什么HashMap初始大小为16,为什么加载因子大小为0.75,这两个值的选取有什么特点?
先看HashMap的定义: public class HashMap<K,V>extends AbstractMap<K,V>implements Map<K,V> ...
- IOS 开发之-- textfield和textview,return键的改变,点击return键
IOS 开发之-- textfield和textview,return键的改变,点击return键 一,textfield的return键改变 方案1.改变键盘右下角的换行(enter)键为完成键,后 ...
- vue-cli脚手架安装和webpack-simple模板项目生成
vue-cli 是一个官方发布 vue.js 项目脚手架,使用 vue-cli 可以快速创建 vue 项目. GitHub地址是:https://github.com/vuejs/vue-cli 一. ...
- PAT L3-016 二叉搜索树的结构
https://pintia.cn/problem-sets/994805046380707840/problems/994805047903240192 二叉搜索树或者是一棵空树,或者是具有下列性质 ...
- promise-笔记
promise 封装Promise var fs = require('fs') function pReadFile(filePath) { return new Promise(function ...