cf492C Vanya and Exams
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
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.
唉其实就是贪心完排个序
结果没有加个(LL)就被x掉了
不开心
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m,k;
LL tot,ans;
struct cla{
int a,b;
}c[1000010];
bool operator <(cla a,cla b)
{return a.b<b.b;}
int main()
{
n=read();m=read();k=read();
for (int i=1;i<=n;i++)
{ c[i].a=read();c[i].b=read();
tot+=c[i].a;
c[i].a=m-c[i].a;
}
tot=(LL)n*k-tot;
if (tot<=0)
{
printf("0\n");
return 0;
}
sort(c+1,c+n+1);
for (int i=1;i<=n;i++)
{
if (!tot)break;
if (c[i].a<=tot)
{
tot-=c[i].a;
ans+=(LL)c[i].b*c[i].a;
}else
if (c[i].a>tot)
{
ans+=(LL)tot*c[i].b;
tot=0;
}
}
printf("%lld\n",ans);
}
cf492C Vanya and Exams的更多相关文章
- 题解 CF492C Vanya and Exams
CF492C Vanya and Exams 有了Pascal题解,来一波C++题解呀qwq.. 简单的贪心题 按b[i]从小到大排序,一个一个学科写直到达到要求即可 #include<cstd ...
- 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 ...
- CodeForces 492C Vanya and Exams (贪心)
C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- codeforces 492C. Vanya and Exams 解题报告
题目链接:http://codeforces.com/problemset/problem/492/C 题目意思:给出 3 个整数:n, r, avg.然后有 n 行,每行有两个数:第 i 行有 ...
- Codeforces Round #280 (Div. 2) A B C 暴力 水 贪心
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CodeForces Round #280 (Div.2)
A. Vanya and Cubes 题意: 给你n个小方块,现在要搭一个金字塔,金字塔的第i层需要 个小方块,问这n个方块最多搭几层金字塔. 分析: 根据求和公式,有,按照规律直接加就行,直到超过n ...
- codeforces492C
Vanya and Exams CodeForces - 492C Vanya wants to pass n exams and get the academic scholarship. He w ...
- Codeforces Round #280 (Div. 2) A , B , C
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
随机推荐
- word-wrap: break-word 和 word-break: break-all 到底有啥区别?
做项目改bug的时候,遇到过好多次,要么是文本超出文本区域,或者单词太长(一般是url链接中的一些鬼),把装它的标签强制撑大,导致一些响应式问题.除此之外,还有很多问题,每次都是恍然醒悟,然后又在网上 ...
- MySQL日期函数
1.已知出生日期,求年龄 SELECT '1992-04-10' as birthday, curdate(), ( YEAR (curdate()) - YEAR ('1992-04-10')-1 ...
- c# 可变性解析(协变和逆变)
之所以会想写关于协变和逆变的知识点,主要是因为在泛型委托中提到了这个知识点. 1.什么是可变性 可变性是.NET4.0中的一个特性,可变形分为:协变性,逆变性,不可变性. 2.在.NET4.0出来之前 ...
- nginx本地的测试环境添加SSL
要在本地添加SSL,首先要做的是防火墙是不是放开了443端口,同时,在nginx安装时是不是支持了ssl模块,这个安装网上很容易找到相关资料 防火墙,个人还是用iptables比较直观 先将selin ...
- Java finally语句到底是在return之前还是之后执行(JVM字节码分析及内部体系结构)?
之前看了一篇关于"Java finally语句到底是在return之前还是之后执行?"这样的博客,看到兴致处,突然博客里的一个测试用例让我产生了疑惑. 测试用例如下: public ...
- 数据库VIEW(视图)
视图是基于 SQL 语句的结果集的可视化的表. 视图包括行和列,就像一个真实的表.视图中的字段就是来自一个或多个数据库中的真实的表中的字段. 我们能够向视图加入 SQL 函数.WHERE 以及 JOI ...
- Oracle11g完全卸载步骤
Oracle11g完全卸载步骤:1. 开始->设置->控制面板->管理工具->服务 停止所有Oracle服务.2. 开始->程序->Oracle - OraHome ...
- Qt之加密算法
在写这篇文章之前,我曾反复思量关于加密的叫法是否准确,更为严格来说,应该是密码散列-将数据(如中英文字母.特殊字符)通过复杂的算法转换为另一种固定长度的值. QCryptographi ...
- samba服务日志文件-密码文件及启停
1.Samba服务日志文件日志文件对于samba非常重要,它存储着客户端访问samba服务器的信息,以及samba服务的错误提示信息等,可以通过分析日志,帮助解决客户端访问和服务器维护等问题.在/et ...
- java鼠标与键盘事件监听
package cn.stat.p3.windowdemo; import java.awt.Button; import java.awt.FlowLayout; import java.awt.F ...