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。
最新文章
- iOS CoreData 中 objectID 的不变性
- MongoDB 分片的原理、搭建、应用
- [复变函数]第06堂课 2.1 解析函数的概念与 Cauchy-Riemann 方程 (续)
- UML类图关系-转
- sdut 2482 二叉排序树
- 多个div并排显示的居中问题&mdash;&mdash;来自腾讯的一道面试题
- 解决Delphi自带UTF8解码缺陷(使用API)
- [Programming WCF Services]Chapter&#160;1.&#160;WCF Essentials - Metadata Exchange
- Halcon算子--区域特征
- cookie特殊字符在游览器被转义
- mysql 数据库链接 过期产品
- python第二十三天-----作业中
- SQLserver 一种简单的GUI方式创建DBlink copy 表数据的方法
- CentOS 7 NAT软路由
- javascript 两张图片切换 三目运算符
- (原创)OpenStack服务如何使用Keystone(三)---详细配置Keystone中间件
- 音频中PCM的概念
- maven 项目目录图与web 应用结构图对比
- QQclient团队博客
- Leetcode 33
热门文章
- ArcGIS 网络分析[2] 在ArcMap中使用网络数据集进行五大网络分析[最短路径/服务区/最近设施点/OD成本矩阵/车辆分配]
- bzoj 4824: [Cqoi2017]老C的键盘
- lumen安装后输出hello world
- php多语言切换---转载
- JQ 为未来元素添加事件处理器—事件委托
- PHP常用功能模块
- Tomcat 到底依赖JRE还是JDK
- Hibernate学习笔记(6)---Criteria接口
- Java第二章----对象和类
- 固定表头,单元格td宽度自适应,多内容出现-横向纵向滚动条数据表格的<;前世今生>;