C. Vanya and Exams
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 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.

Sample test(s)
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.

<pre name="code" class="cpp" style="color: rgb(34, 34, 34);">/*题目大意:Vanya想获得奖学金,条件是她所有科目的平均分要达到avg,当然没有达到也是没有关系滴、可以通过
* 写文章来加分、这就好比每年综合测评时候有的同学文化成绩不行还可以通过这加分那加分来补一样、相应科目加上一分
* 要写多少文章告诉你,让你求出最少写多少文章能够获得奖学金
*输入:n,代表科目数量、r,代表 每门课最高达到的分数,avg,表示平均分。接下来的n行表示第i门课的分数与在该门课
* 上面加上一分所要写出的文章数量
*输出:最少写的文章数量
*算法分析:采用贪心策略,写文章肯定是写那种写得数量少加上一分的、
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
using namespace std; typedef long long int LL ; struct node {
LL x, y;
}a[100010]; int cmp(node c, node b) {
return c.y < b.y;
} int main() {
memset(a, 0, sizeof(a)); LL n, r, avg;
cin >> n >> r >> avg;
for (LL i = 0; i<n; i++)
cin >> a[i].x >> a[i].y;
LL res = n *avg;
LL sum = 0;
for (LL i = 0; i<n; i++)
sum += a[i].x;
LL p = res - sum;
if (p > 0) {
res = 0;
sort(a, a+n, cmp);
LL f = 0, flag1 = 1;
for (LL i = 0; i<n && flag1; i++) {
if (a[i].x < r && f < p) {
int flag = r-a[i].x;
f += flag;
if (f <= p) {
res += flag*a[i].y;
}
else {
f -= flag;
int p1 = p-f;
res += a[i].y*p1;
flag1 = 0;
break;
} }
}
cout << res << endl;
}
else
cout << 0<< endl;
return 0;
}

没有AC不了的题,只有不努力的ACMer。


Codeforces Round #280 (Div. 2)_C. Vanya and Exams的更多相关文章

  1. Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心

    C. Vanya and Exams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...

  2. Codeforces Round #280 (Div. 2) E. Vanya and Field 数学

    E. Vanya and Field Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...

  3. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 二分

    D. Vanya and Computer Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  4. Codeforces Round #280 (Div. 2)E Vanya and Field(简单题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vany ...

  5. Codeforces Round #280 (Div. 2) E. Vanya and Field 思维题

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 预处理

    D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  7. Codeforces Round #280 (Div. 2) A. Vanya and Cubes 水题

    A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学

    D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  9. 水题 Codeforces Round #308 (Div. 2) A. Vanya and Table

    题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...

随机推荐

  1. java的运行机制(基础)

    1:高级语言的运行机制: 我们编程都是用的高级语言(写汇编和机器语言的大牛们除外),计算机不能直接理解高级语言,只能理解和运行机器语言,所以必须要把高级语言翻译成机器语言,计算机才能运行高级语言所编写 ...

  2. 解析JSON的两种方法eval()和JSON.parse()

    解析JSON 一种方法是使用eval函数. var dataObj = eval("("+json+")"); 必须把文本包围在括号中,这样才能避免语法错误,迫 ...

  3. 记录优雅的pythonic代码

    记录平时学习中接触到的和网上看到的一些pythonic的方法,只为日后查询时候方便. 1.列表推导式: seq_list=[1,2,3,4,5] new_list=[i *2 for i in seq ...

  4. thinkphp 3.1.3 redis 只能读取 无法写入的问题

    找到thinkphp的目录 thinkphp\Extend\Driver\Cache    下面的Redis    大概在81行足有 // if(is_int($expire)) { // redis ...

  5. KVO键值观察的具体实现

    1.KVO简介 KVO是Objective-C对观察者设计模式的一种实现,它提供一种机制,指定一个被观察对象(如A类),当对象中的某个属性发生变化的时候,对象就会接收到通知,并作出相应的处理.在MVC ...

  6. SQL基础学习_05_函数、谓词、CASE表达式

    函数 算术函数 1. 四则运算: +.-.*./  2. ABS:求绝对值, ABS(数值) 3. MOD: 求余,MOD(被除数,除数) 4. ROUND:四舍五入,ROUND(对象数值,保留小数的 ...

  7. appium-chromedriver@3.0.1 npm ERR! code ELIFECYCLE npm ERR! errno 1

    解决方法: npm install appium-chromedriver@3.0.1 --ignore-scripts 或者(安装方法): npm install appium-chromedriv ...

  8. pl/sql command window 初步接触

    pl/sql command window基本操作 PL/SQL Developer应用两年了,今天第一次应用command window. command window类似于sqlplus窗口: 1 ...

  9. 虚拟机迁移(QEMU动态迁移,Libvirt动(静)态迁移)

    动静态迁移的原理 静态迁移是指在虚拟机关闭或暂停的情况下,将源宿主机上虚拟机的磁盘文件和配置文件拷贝到目标宿主机上.这种方式需要显式的停止虚拟机运行,对服务可用性要求高的需求不合适. *** 动态迁移 ...

  10. python实现类jq的json路径过滤

    开发过程中访问接口时经常用到jq来过滤json,用着觉得不是很爽,于是自己搞一个舒服的 ^_^ 先说需求: 输入:参数1:被过滤对象(json.dict.list), 参数2:过滤路径 输出:过滤结果 ...