Codeforces Round #280 (Div. 2)-C. Vanya and Exams (贪心)_html/css_WEB-ITnose

WBOY
发布: 2016-06-24 11:53:06
原创
1201 人浏览过

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

input

5 5 45 24 73 13 22 5
登录后复制

output

input

2 5 45 25 2
登录后复制

output

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.






题意:Vanya修了n门课,第i门课的学分是ai,已知每门课的最高学分不能超过r,而且他想得奖学金,但是获得奖学金的要求是:他的所有课的平均学分不得低于avg,如果不满足的话,他就不得不写论文去增加自己的学分,已知第i门课要增加1学分的话,必须写bi篇论文,由于,他比较懒, 所以让你计算最少他需要写多少篇论文才能获得奖学金。


分析:贪心。这个就是多了个限定条件??每门课的学分不能超过r,我们可以判断他的平均学分是不是满足条件了,若是,则直接输出0即可;否则,将所有课按bi排序,每次都在学分不超过r的条件下,去选择bi最小的那门课去修,直到学分等于r了,我们就再去选择当前已得学分小于r的且bi最小的去修,直到他的学分满足条件即可。这样,我们得到的结果,就是最小的结果。




AC代码:

#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define INF 0x7ffffffftypedef struct{    long long a, b;}node;node m[100005];int cmp(node x, node y){    return x.b = r) i++;            else{                int x = min(r - m[i].a, foo-k);                ans += x * m[i].b;                m[i].a += x;                k += x;            }        }        printf("%lld\n", ans);    }    return 0;}</time.h></stdlib.h></math.h></string></map></set></queue></vector></algorithm></iostream></string.h></stdio.h>
登录后复制



心得:开始上来直接贪心 + 暴力,结果在第13个样例上超时了,所以就优化了一下。还是最优的代码好呀。一定不能得过且过,有好的方法,如果不是太麻烦的话,还是优化的好^_^



来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!