Codeforces Round #280 (Div. 2)_C. Vanya and Exams
1 second
256 megabytes
standard input
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?
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).
In the first line print the minimum number of essays.
5 5 4
5 2
4 7
3 1
3 2
2 5
4
2 5 4
5 2
5 2
0
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #280 (Div. 2)E Vanya and Field(简单题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vany ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 水题 Codeforces Round #308 (Div. 2) A. Vanya and Table
题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...
随机推荐
- 调用CMD命令的一个.NET工具类(MyWindowsCmd)
功能大概描述一下如果直接StandardOutput.ReadToEnd()这种方法,有很多限制 这类方式必须把命令全部执行一次写入并标记为exit,而且返回内容的获取会一直等待,如果在主线程里使用会 ...
- ES6 let和const命令(3)
const 用来声明常量.一旦声明,就不能改变. const在声明必须初始化,只声明不赋值会出错 const的作用域与let一样,只在声明的块级作用域有效. const命令声明的常量也不提升,同样存在 ...
- 串口调试者v2.1------开源c#串口调试工具
第一步:上图 第二步:上代码 >>>>>>>>>>>源代码下载<<<<<<<<< ...
- 如何减轻ajax定时触发对服务器造成的压力和带宽的压力?ajax-长轮训
AJAX长轮询的方法来解决频繁对后台的请求,进一步减小压力 在实现过程发现AJAX的多次请求会出现多线程并发的问题又使用线程同步来解决该问题 个人对ajax长轮询的一点愚见 ajax请示后台时,后台程 ...
- Shader 1:能接受阴影的透明shader
第一次接触Shader,项目需要,直接说需求吧,需要一个透明并且能接受阴影的shader.unity系统自带的shader已经满足不了了.上一段代码吧 Shader "GreenArch/T ...
- Struts2-整理笔记(二)常量配置、动态方法调用、Action类详解
1.修改struts2常量配置(3种) 第一种 在str/struts.xml中添加constant标签 <struts> <!-- 如果使用使用动态方法调用和include冲突 - ...
- 程序猿的日常——HashMap的相关知识
背景知识 哈希冲突 哈希是指通过某种方法把数据转变成特定的数值,数值根据mod对应到不同的单元上.比如在Java中,字符串就是通过每个字符的编码来计算.数字是本身对应的值等等,不过就算是再好的哈希方法 ...
- PHP中引入文件的四种方式及区别
文件加载语句:include,require,include_once,require_once include,require: require函数通常放在 PHP 程序的最前面,PHP 程序在执行 ...
- Xamarin.android 重写axml控件
https://www.cnblogs.com/lonelyxmas/p/5632694.html <Laco: 用来用引指定的控件 android:layout_widt ...
- 洛谷 P1485 火枪打怪
题目描述 LXL进入到了一片丛林,结果他发现有n只怪物排成一排站在他面前.LXL有一杆火枪能对付这些怪物.他知道从左至右数第i只怪物的血量是mi.现在LXL可以将一些子弹射向某个怪物.LXL可以控制他 ...