CF#280 (Div. 2) C.(贪心)
来源:互联网 发布:中科院云计算的股票 编辑:程序博客网 时间:2024/05/14 22:22
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 45 24 73 13 22 5
4
2 5 45 25 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.
解题思路:
题目大意就是给你n门功课,每门功课的最大分数r,总的平均分avg。接下来给出n行,每行a代表该门功课实际得的分数,b代表发表b篇文章可以使a涨一分(最高不超过r)。
首先如果当前的平均分大于等于给出的平均分,那么直接输出0;否则要算出需要发表多少篇文章才可以到达平均分,即key = avg * n - sum1,sum1为实际所有门功课的和,很容易推导出这个式子。
接下来按照b从小到大排个序,每次贪b小的,知道当前这门功课的分数等于r。不能再涨为止。
最后注意开成__int64,int会WA,第四组数据特别大·····
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef __int64 LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;const int maxn = 100001;LL n , r , avg;struct node{ LL a , b;}s[maxn];bool cmp(node x , node y){ if(x.b == y.b) return x.a < y.a; return x.b < y.b;}int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif while(~scanf("%I64d%I64d%I64d",&n,&r,&avg)) { LL sum1 = 0; for(int i = 0 ; i < n ; i ++) { scanf("%I64d%I64d",&s[i].a , &s[i].b); sum1 += s[i].a; } if(sum1 / (double) n - avg > EPS) { printf("0\n"); continue; } sort(s , s + n , cmp); LL key = avg * n - sum1; LL res = 0; for(int i = 0 ; i < n ; i ++) { if(s[i].a >= r) continue; if(r - s[i].a <= key && key != 0) { res += (r - s[i].a) * s[i].b; key -= r - s[i].a; } else { res += key * s[i].b; break; } } printf("%I64d\n",res); }}
- CF#280 (Div. 2) C.(贪心)
- CF#274 (Div. 2) C.(贪心+排序)
- C. Developing Skills (CF Round #322 (Div.2) 贪心)
- CF#257 (Div. 2) C.
- CF#FF (Div. 2) C.
- CF#266 (Div. 2) C
- CF 332 C 贪心
- CF 508C///贪心
- CF 387C 贪心
- CF #347 (Div.2) B. Rebus(贪心)
- cf Round #202 (div.2) C ------------ Mafia
- CF Round #240 (Div. 2) C
- CF#282 Div 2 C Treasure
- CF #363 C (div.2) Vacations
- CF #77 Div 1 C ,Div 2 D
- CF div2 231 C(贪心)
- CF 600C 贪心+字符串
- CF 342div2 C 贪心
- HDU 5113 Black and White(搜索)
- Versions For Mac 出现 SVN Working Copy xxx locked
- HEVC代码追踪(十一。一):运动估计/补偿之xCheckRDCostInter
- 大白话解读KBEngine服务器引擎——第四期——新建Unity3D+KBEngine的工程
- 第十四周上机项目3.2
- CF#280 (Div. 2) C.(贪心)
- jQuery介绍及语法
- 一些管理学基础知识
- android 学习源码下载
- 数字最小k分割(算法上机)
- wireshark过滤规则
- sqlmap源码阅读之基础(dict,sys)
- Oracle_oracle 11g数据库 安装教程1
- Java中byte与16进制字符串的互相转换