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/problem/C
Description
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 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.
Sample Input
5 5 4
5 2
4 7
3 1
3 2
2 5
Sample Output
4
HINT
题意
有一个人有n门课程,每一门课程他最多获得r学分,他只要所有课程的平均学分有avg,他就可以获得奖学金
每门课程,他已经获得了ai学分,剩下的每一个学分,都需要写bi篇论文才能得到
然后问你,这个人最少写多少论文才能获得奖学金
题解:
贪心,我们选择bi最小的开始写论文,然后扫一遍就好了,直到学分够为止
代码
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std; #define maxn 100005
pair<long long,long long> p[maxn];
int main()
{
int n;
long long r,avg;
scanf("%d%lld%lld",&n,&r,&avg);
avg*=n;
for(int i=;i<n;i++)
{
scanf("%lld%lld",&p[i].second,&p[i].first);
avg-=p[i].second;
p[i].second = r - p[i].second;
}
sort(p,p+n);
long long ans = ;
for(int i=;i<n;i++)
{
if(avg<=)break;
if(p[i].second>=avg)
{
ans+=avg*p[i].first;
break;
}
else
{
ans+=p[i].second*p[i].first;
avg-=p[i].second;
}
}
printf("%lld\n",ans);
}
Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心的更多相关文章
- Codeforces Round #280 (Div. 2)_C. Vanya and Exams
C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 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 #481 (Div. 3) G. Petya's Exams (贪心,模拟)
题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你 ...
随机推荐
- 解决:Unable to connect to repository https://dl-ssl.google.com/android/eclipse/site.xml
ailed to fectch URl https://dl-ssl.google.com/android/repository/addons_list.xml, reason: Connection ...
- redis 和 bloom filter
今天打算使用redis 的bitset搞一个 bloom filter, 这样的好处是可以节省内存,坏处是可能在会有一些数据因为提示重复而无法保存. bloom filter 的大体原理就是通过不同的 ...
- 白盒测试之gmock入门篇
一.gmock是什么 gmock是google公司推出的一款开源的白盒测试工具.gmock是个很强大的东西,测试一个模块的时候,可能涉及到和其他模块交互,可以将模块之间的接口mock起来,模拟交互过程 ...
- new trip
离开YY已经快一周了,特别感谢以前的老大姚冬和朱云峰,从他俩身上学到了很多.这个决定也经过了很长的纠结,不想再做个犹豫不决的人,所以最后还是坚定了最初的信念,也算是对半年前自己的一个完好交代,以防将来 ...
- iOS开发常用输入校验
1.数字字符校验 #define NUMBERSPERIOD @"0123456789." - (BOOL)CheckInput:(NSString *)string { NSCh ...
- Tsinsen A1219. 采矿(陈许旻) (树链剖分,线段树 + DP)
[题目链接] http://www.tsinsen.com/A1219 [题意] 给定一棵树,a[u][i]代表u结点分配i人的收益,可以随时改变a[u],查询(u,v)代表在u子树的所有节点,在u- ...
- ASP.NET MVC3 系列教程 – Web Pages 1.0
http://www.cnblogs.com/highend/archive/2011/04/14/aspnet_mvc3_web_pages.html I:Web Pages 1.0中以“_”开头的 ...
- [Hive - Tutorial] Querying and Inserting Data 查询和插入数据
Querying and Inserting Data Simple Query Partition Based Query Joins Aggregations Multi Table/File I ...
- J2EE开发常用开源框架技术(转)
1持久层:1)Hibernate这个不用介绍了,用的很频繁,用的比较多的是映射,包括继承映射和父子表映射对 于DAO在这里介绍个在它基础上开发的包bba96,目前最新版本是bba96 2.0它对Hib ...
- 第二百八十八天 how can I坚持
明天,就要回济南了.早上八点的票,去火车站还得一个半小时,六点就得起床啊,好早,忍了. 这两天又没法更新日志了.周一才能回来. 今天好忙,事情好杂. 其实不想请假. 算了,睡觉了,没什么可写的了.是没 ...