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 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 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 贪心的更多相关文章

  1. 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 ...

  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 #481 (Div. 3) G. Petya's Exams (贪心,模拟)

    题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你 ...

随机推荐

  1. 【Struts】服务器文件的上传和下载

    Java中获得文件的文件后缀 import java.io.*; public class FileTest{ public static void main(String args[]){ File ...

  2. 简单易用的AOP/IOC框架

    Source: http://www.codeproject.com/KB/Articles/684613/Working/AopIoc.zip Introduction Supper framewo ...

  3. $( ).focus()与$( )[0].focus()区别

    $( #id).focus()与$( #id)[0].focus()没有区别,因为id必须是唯一的.如果同一页面出现多个相同的ID(这是不符合w3c规范的),$(#id)也只会拿到第一个该ID,后面的 ...

  4. Chrome 实用调试技巧

    Chrome 实用调试技巧 2016-07-23 如今Chrome浏览器无疑是最受前端青睐的工具,原因除了界面简洁.大量的应用插件,良好的代码规范支持.强大的V8解释器之外,还因为Chrome开发者工 ...

  5. js函数——倒计时模块+无缝滚动

    倒计时 效果: 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  6. Android入门:发送HTTP的GET和POST请求

    HTTP的请求详解在我的博客中已经讲解过: http://blog.csdn.net/xiazdong/article/details/7215296 我在http://blog.csdn.net/x ...

  7. IOS PUSH

    第一阶段:.net应用程序把要发送的消息.目的iPhone的标识打包,发给APNS. 第二阶段:APNS在自身的已注册Push服务的iPhone列表中,查找有相应标识的iPhone,并把消息发到iPh ...

  8. 如何避免JavaScript的内存泄露及内存管理技巧

    发表于谷歌WebPerf(伦敦WebPerf集团),​​2014年8月26日. 高效的JavaScript Web应用必须流畅,快速.与用户交互的任何应用程序,都需要考虑如何确保内存有效使用,因为如果 ...

  9. Python对象初探

    数据结构 PyObject_HEAD //对象公共头部   Py_ssize_t ob_refcnt; //对象引用数 PyTypeObject *ob_type; //对象类型 PyObject_V ...

  10. 最短路+线段交 POJ 1556 好题

    // 最短路+线段交 POJ 1556 好题 // 题意:从(0,5)到(10,5)的最短距离,中间有n堵墙,每堵上有两扇门可以通过 // 思路:先存图.直接n^2来暴力,不好写.分成三部分,起点 终 ...