C. Vanya and Exams
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output 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?

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 test(s)
input
  1. 5 5 4
    5 2
    4 7
    3 1
    3 2
    2 5
output
  1. 4
input
  1. 2 5 4
    5 2
    5 2
output
  1. 0
Note

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掉了

不开心

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<queue>
  8. #include<deque>
  9. #include<set>
  10. #include<map>
  11. #include<ctime>
  12. #define LL long long
  13. #define inf 0x7ffffff
  14. #define pa pair<int,int>
  15. #define pi 3.1415926535897932384626433832795028841971
  16. using namespace std;
  17. inline LL read()
  18. {
  19. LL x=0,f=1;char ch=getchar();
  20. while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  21. while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  22. return x*f;
  23. }
  24. int n,m,k;
  25. LL tot,ans;
  26. struct cla{
  27. int a,b;
  28. }c[1000010];
  29. bool operator <(cla a,cla b)
  30. {return a.b<b.b;}
  31. int main()
  32. {
  33. n=read();m=read();k=read();
  34. for (int i=1;i<=n;i++)
  35. {
  36.  
  37. c[i].a=read();c[i].b=read();
  38. tot+=c[i].a;
  39. c[i].a=m-c[i].a;
  40. }
  41. tot=(LL)n*k-tot;
  42. if (tot<=0)
  43. {
  44. printf("0\n");
  45. return 0;
  46. }
  47. sort(c+1,c+n+1);
  48. for (int i=1;i<=n;i++)
  49. {
  50. if (!tot)break;
  51. if (c[i].a<=tot)
  52. {
  53. tot-=c[i].a;
  54. ans+=(LL)c[i].b*c[i].a;
  55. }else
  56. if (c[i].a>tot)
  57. {
  58. ans+=(LL)tot*c[i].b;
  59. tot=0;
  60. }
  61. }
  62. printf("%lld\n",ans);
  63. }

cf492C Vanya and Exams的更多相关文章

  1. 题解 CF492C Vanya and Exams

    CF492C Vanya and Exams 有了Pascal题解,来一波C++题解呀qwq.. 简单的贪心题 按b[i]从小到大排序,一个一个学科写直到达到要求即可 #include<cstd ...

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

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

  4. CodeForces 492C Vanya and Exams (贪心)

    C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. codeforces 492C. Vanya and Exams 解题报告

    题目链接:http://codeforces.com/problemset/problem/492/C 题目意思:给出 3 个整数:n,  r,  avg.然后有 n 行,每行有两个数:第 i 行有 ...

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

  7. CodeForces Round #280 (Div.2)

    A. Vanya and Cubes 题意: 给你n个小方块,现在要搭一个金字塔,金字塔的第i层需要 个小方块,问这n个方块最多搭几层金字塔. 分析: 根据求和公式,有,按照规律直接加就行,直到超过n ...

  8. codeforces492C

    Vanya and Exams CodeForces - 492C Vanya wants to pass n exams and get the academic scholarship. He w ...

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

随机推荐

  1. UUID详解

    什么是UUID? UUID是Universally Unique Identifier的缩写,它是在一定的范围内(从特定的名字空间到全球)唯一的机器生成的标识符.UUID具有以下涵义: 经由一定的算法 ...

  2. 【转】ASP.NET MVC框架下使用MVVM模式-KnockOutJS+JQ模板例子

    KnockOutJS学习系列----(一) 好几个月没去写博客了,最近也是因为项目紧张,不过这个不是借口,J. 很多时候可能是因为事情一多,然后没法静下来心来去写点东西,学点东西. 也很抱歉,突然看到 ...

  3. BLOG PLUGINS

    文章分享按钮 (1)加网(JiaThis) (2)百度分享 文章关联推荐 每篇博文下面可以显示你博客中与该篇博文有些关联的几篇文章,也就是智能推荐,一方面可以增加你博文的曝光率和点击率,一方面也可以给 ...

  4. .net 面试题(3)

    96.题目: 活期存款中,"储户"通过"存取款单"和"储蓄所"发生联系.假定储户包括:账号,姓名,电话,地址,存款额:"储蓄所&q ...

  5. Java使用poi包读取Excel文档

    项目需要解析Excel文档获取数据,就在网上找了一些资料,结合自己这次使用,写下心得: 1.maven项目需加入如下依赖: <dependency> <groupId>org. ...

  6. MySQL添加外键的方法

    为book表添加外键: <1>明确指定外键的名称: 语法:alter table 表名 add constraint 外键的名称 foreign key(你的外键字段名) REFERENC ...

  7. linux文件解-压缩

    常用: 解压tar.gz包  使用命令:tar -zxvf  file.tar.gz   -z 指有gzip的属性  -x 解开一个压缩文件的参数  -v解压过程中显示文件  -f放最后接filena ...

  8. Web应用程序项目XXXX已配置为使用IIS。无法访问IIS元数据库。您没有足够的特权访问计算机上的IIS网站

    问题:Windows8下直接使用VS打开项目,出现问题:XXXX已配置为使用IIS.无法访问IIS元数据库.您没有足够的特权访问计算机上的IIS网站.解决:1.以“管理员权限”运行VS,在VS菜单打开 ...

  9. css如何实现背景透明,文字不透明?

    之前做了个半透明弹层,但设置背景半透明时,子元素包含的字体及其它元素也都变成了半透明.对opacity这个属性认识的不透彻,在这里做一些总结,方便以后使用.   背景透明,文字不透明的解决方法:   ...

  10. jQuery Scroll div滚动条样式更改

    <script type="text/javascript" src="js/jquery-1.2.6.min.js"></script> ...