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. 【原码笔记】-- protobuf.js 与 Long.js

    protobuf.js的结构和webpack的加载之后的结构很相似.这样的模块化组合是个不错的结构方式.1个是适应了不同的加载方式,2个模块直接很独立.webpack的功能更全一点.但如果自己封装js ...

  2. [置顶] xamarin android使用zxing扫描二维码

    好久没写了,这片文章篇幅不长,概述一下在xamarin android中用 ZXing.Net.Mobile库扫描二维码读取url的示例.扫码支付,扫码登录,App上各种各样的扫码,好像没个扫码的就有 ...

  3. 从源码(编译)安装golang

    从源码安装golang 通常情况下,安装go只需要在官网(https://golang.org/dl/)下载适合系统的二进制发布包,按照安装说明进行安装即可. 对于Linux, Mac OS X和Fr ...

  4. [编织消息框架][JAVA核心技术]异常应用

    QException是项目业务异常基类 按模块划分子类异常,方便定位那块出错 有个来源码属性code作用定位某个功能处理出错逻辑,数字类型节省内存空间,同时减少创建子类的子类 QSocketExcep ...

  5. 二:mysql安装配置、主从复制配置详解

    作者:NiceCui 本文谢绝转载,如需转载需征得作者本人同意,谢谢. 本文链接:http://www.cnblogs.com/NiceCui/p/8213723.html 邮箱:moyi@moyib ...

  6. Django学习日记06_视图_URLconf、View

    URLconf Django通过URLconf来响应网页请求,在项目设置settings.py中,设定了ROOT_URLCONF值来指定默认的URLconf(即mysite.urls),当HTTPRe ...

  7. CSS3 radial-gradient 径向渐变属性 实现重复半圆角内边框

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8gAAADiCAIAAAAd73mYAAAG+ElEQVR4nO3dQQrkNhCG0TntHGGu4U ...

  8. 第十五章:Python の Web开发基础 (二) JavaScript与DOM

    本課主題 JavaScript 介绍 DOM 介绍 JavaScript 介绍 JavaScript 是一门编程语言,它可以让网页动起来的,JavaScript 的变量有两种,一个是局部变量:一个是全 ...

  9. FFmpeg AVCodec

    FFmpeg编解码 FFmpeg支持绝大多数视频编解码格式,如何遍历FFmpeg编解码器? 编解码器以链表形式存储,使用av_codec_next() 函数可以获取编解码器指针,当参数为NULL时,获 ...

  10. Python模块学习------ 多线程threading(2)

    一.避免使用thread模块,使用threading模块的原因: 1. 更高级别的threading模块更为先进,对线程的支持更加完善.而且使用thread模块的属性有可能会与threading 出现 ...