CodeForces 492C 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 思路: 平均分其实乘一下n以后就是总分,也就是说总分要达到这个sum=avg*n,而每一科提升一分的代价是bi个论文,提升空间则还有r-ai个学分。计算好每个科目以后,贪心取代价最小的,按bi从小到大排序,能取多少就取多少,直到分数达到sum为止,性价比最高的科目的提分空间用完以后再去性价比第二高的科目。
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const int INF = 1e9;
const double eps = 1e-;
//const int N = ;
int cas = ; ll n,r,avg,sum; void run()
{
ll a,b;
vector<pii> v;
sum = avg * n;
for(int i = ; i < n; i++ )
{
cin >> a >> b;
sum -= a;
v.push_back(make_pair(b,r-a));
}
sort(v.begin(),v.end());
ll ans = ;
for(int i = ; i < n; i++ )
{
if(sum <= ) break;
if(sum >= v[i].second)
ans+=v[i].first*v[i].second, sum-=v[i].second;
else
ans += sum*v[i].first, sum -= sum;
}
cout << ans << endl;
} int main()
{
#ifdef LOCAL
// freopen("case.txt","r",stdin);
#endif
while(cin >> n >> r >> avg)
run();
return ;
}
CodeForces 492C Vanya and Exams (贪心)的更多相关文章
- codeforces 492C. Vanya and Exams 解题报告
题目链接:http://codeforces.com/problemset/problem/492/C 题目意思:给出 3 个整数:n, r, avg.然后有 n 行,每行有两个数:第 i 行有 ...
- 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/pr ...
- 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 ...
- cf492C Vanya and Exams
C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 题解 CF492C Vanya and Exams
CF492C Vanya and Exams 有了Pascal题解,来一波C++题解呀qwq.. 简单的贪心题 按b[i]从小到大排序,一个一个学科写直到达到要求即可 #include<cstd ...
- codeforces 492E. Vanya and Field(exgcd求逆元)
题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走 ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- Codeforces 677D Vanya and Treasure 暴力+BFS
链接 Codeforces 677D Vanya and Treasure 题意 n*m中有p个type,经过了任意一个 type=i 的各自才能打开 type=i+1 的钥匙,最初有type=1的钥 ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
随机推荐
- 【二】MongoDB入门
下面是mongodb的一些基本概念: 文档是MongoDB中数据的基本单元,类似关系数据库中的行. 集合,是存储文档的容器,类似关系数据库中的表. MongoDB的单个实例容纳多个数据库,每个数据库都 ...
- PHP新写的大转盘抽奖源码
中奖概率 抽奖大转盘演示:http://www.sucaihuo.com/php/3301.html function getRand($proArr, $proCount) { $result = ...
- SQl Server 中登录名 、用户、角色、概念一览
转载:http://www.2cto.com/database/201306/216922.html 数据库,角色,用户,安全 登录SQL server 2008可以用w ...
- Linux- 运维
Linux运维遇到需要使用命令 查看Linux系统有多少用户 cat /etc/passwd | wc -l 查看用户占用的uid,默认情况下,ldap新增的用户和系统本地的用户uid是混在一起.在新 ...
- Hive- 表
在hive中表的类型:管理表和托管表(外部表). 内部表也称之为MANAGER_TABLE,默认存储在/user/hive/warehouse下,也可以通过location指定:删除表时,会删除表的数 ...
- SQL嵌套子查询和相关子查询的执行过程有什么区别(推荐)
SQLServer子查询可以分为 相关子查询 和 嵌套子查询 两类.前提, 假设Books表如下: 类编号 图书名 出版社 价格 ----------------------------------- ...
- python-多线程趣味
假设一个程序员,想听歌,但是又想敲代码,于是又: 我听完歌就去敲代码: #! /usr/bin/env python #coding=utf-8 import time def matter1(mus ...
- 热门游戏 2048 C++ 源代码分享
/*By Reason*/ #include<iostream> #include <iomanip> #include<math.h> #include<s ...
- 数据库连接池(connection pool)
1.JDBC数据库连接池的必要性 在使用开发基于数据库的web程序时,传统的模式基本是按以下步骤: – 在主程序(如servlet.beans)中建立数据库连接. – 进行sql ...
- Android之SharedPreferences权限
import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; pub ...