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题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
随机推荐
- 【leetcode刷题笔记】Implement strStr()
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...
- 前端开发笔记--flex布局
flex布局: 个人觉得flex布局比起传统布局要优先得多(主要是容易使用),缺点是IE10及以上版本才能使用,甚至某些属性只有在IE11才能使用(而且我发现凡是不兼容主要IE的坑来的多,不是说其他浏 ...
- BootStrap实现左侧或右侧竖式tab选项卡
BootStrap实现左侧或右侧竖式tab选项卡 代码如下: <div style="height: 100px;"> <div class="col- ...
- 纯CSS3垂直动画菜单
在线演示 本地下载
- hd acm1018
Problem Description In many applications very large integers numbers are required. Some of these app ...
- FastReport5的安装
1.运行recompile.exe,选择相应的delphi版本,选择recompile to chinese,编译: 2.选择recompile all pakages,编译: 3.将lib目录下的d ...
- php设计模式课程---6、策略模式如何使用
php设计模式课程---6.策略模式如何使用 一.总结 一句话总结:比如代码需求,做一饭店,有南北方不同菜系,不同分店有不同的饭菜汤的需求,代码怎么设计 从饭店有特色过渡到厨师有特色(南方厨师(南方饭 ...
- mysql 如何创建索引
mysql 如何创建索引 一.总结 一句话总结:MySQL中可以使用alter table这个SQL语句来为表中的字段添加索引. 使用alter table语句来为表中的字段添加索引的基本语法是:AL ...
- 分享知识-快乐自己:Liunx-大数据(Hadoop)初始化环境搭建
大数据初始化环境搭建: 一):大数据(hadoop)初始化环境搭建 二):大数据(hadoop)环境搭建 三):运行wordcount案例 四):揭秘HDFS 五):揭秘MapReduce 六):揭秘 ...
- IIS 高并发导致log记录不完全
项目测试性能过程中,对于高并发测试过程中发现log记录缺失一部分,经过调查,找到了原因是因为IIS连接数的限制,经过修改连接数,成功完成.设置如下: “点击网站”->“右击切换到功能视图”-&g ...