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. js中json与数组字符串的相互转化

    <SCRIPT LANGUAGE="JavaScript"> var t="{'firstName': 'cyra', 'lastName': 'richar ...

  2. AFNetworking速成教程

    转:http://palmsky.net/?p=4138 本文是由 iOS Tutorial 小组成员 Scott Sherwood撰写,他是一个基于位置动态加载(Dynamically Loaded ...

  3. Reading or Writing to Another Processes Memory in C# z

    http://www.jarloo.com/reading-and-writing-to-memory/ Declarations [Flags] public enum ProcessAccessF ...

  4. bzoj3884: 上帝与集合的正确用法 欧拉降幂公式

    欧拉降幂公式:http://blog.csdn.net/acdreamers/article/details/8236942 糖教题解处:http://blog.csdn.net/skywalkert ...

  5. IOS PUSH 实践操作~~~~

    1.推送过程简介        (1)App启动过程中,使用UIApplication::registerForRemoteNotificationTypes函数与苹果的APNS服务器通信,发出注册远 ...

  6. 动态执行linq 语句 NLinq

    using Evaluant.NLinq.Memory;using System.Collections.Generic;using Evaluant.NLinq;using System.Colle ...

  7. MVC和WebForm的优缺点对比

    1 WebForm优点 1)支持事件模型开发,得益于丰富的服务端组件,WebForm开发可以迅速的搭建Web应用 2)使用方便,入门容易 3)控件丰富的WebForm 2 WebForm缺点  1)封 ...

  8. SQL中以count及sum为条件的查询

    在开发时,我们经常会遇到以“累计(count)”或是“累加(sum)”为条件的查询.比如user_num表: id user num 1 a 3 2 a 4 3 b 5 4 b 7   例1:查询出现 ...

  9. redis在mac上的安装

    mac 上安装 redis 首先必须保证mac 已经安装 xcode. 因为make时要用到 Xcode 的command Tools . (1)下载 redis   http://redis.goo ...

  10. lamda表达式相关知识

    lamda表达式写法 dt = datado.SelectDalMeath(sqlStr.ToString()); var x = (from r in dt.AsEnumerable() selec ...