Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心
2014-12-02 09:10
295 查看
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 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).
Output
In the first line print the minimum number of essays.
Sample test(s)
Input
Output
Input
Output
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.
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 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).
Output
In the first line print the minimum number of essays.
Sample test(s)
Input
5 5 4 5 2 4 7 3 1 3 2 2 5
Output
4
Input
2 5 4 5 2 5 2
Output
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.
//排序,排完之后再从最小的开始加就Ok #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) struct point{ int a; int b; }; bool cmp(point k,point m) { return k.b<m.b; } point num[100010]; int main() { ll n,r,avg; cin>>n>>r>>avg; avg=n*avg; ll sum=0; for(int i=0;i<n;i++) { scanf("%d%d",&num[i].a,&num[i].b); sum+=num[i].a; } sort(num,num+n,cmp); int kmp=0; ll ans=0; if(sum<avg){ while(1) { sum+=(r-num[kmp].a); ans+=(r-num[kmp].a)*num[kmp].b; kmp++; if(sum>=avg) break; //cout<<ans<<endl; //cout<<sum<<endl; } cout<<ans-(sum-avg)*num[kmp-1].b<<endl; return 0; } cout<<ans<<endl; return 0; }
相关文章推荐
- Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心
- Codeforces Round 280 Div2 B Vanya and Lanterns(binary serch)
- Codeforces Round #280 (Div. 2)A. Vanya and Cubes(简单计算)
- Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学+预处理
- Codeforces Round #280 (Div. 2) E. Vanya and Field (数学GCD)
- Codeforces Round #324 (Div. 2) C. Marina and Vasya(贪心)
- Codeforces Round #374 (Div. 2) D. Maxim and Array 贪心
- 【Codeforces Round 330 (Div 2)E】【贪心 暴力】Edo and Magnets 给定矩形最多去除m个,最小面积矩形使得覆盖所有小矩形重心
- Codeforces Round #235 (Div. 2) A. Vanya and Cards
- 【Codeforces Round 326 (Div 2)C】【贪心】Duff and Weight Lifting 每次取数二的幂数最小取数次数
- Codeforces Round #419 (Div. 2) C. Karen and Game【贪心】
- 【Codeforces Round 365 (Div 2)C】【贪心 极限阻碍思想】 Chris and Road 过马路不被凸包车碰撞的最小时间
- Codeforces Round #253 (Div. 2) D. Andrey and Problem (贪心+数学概率)
- Codeforces Round #169 (Div. 2) D. Little Girl and Maximum XOR(贪心,中等)
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution【逆向思维+贪心】
- 【Codeforces Round 324 (Div 2)E】【贪心 构造】Anton and Ira 全排列交换 最小距离成本
- Codeforces Round #410 (Div. 2) D. Mike and distribution(贪心)
- Codeforces Round #252(Div. 2) 441B. Valera and Fruits 贪心
- Codeforces Round #177 (Div. 1) C. Polo the Penguin and XOR operation(贪心)
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A map B贪心 C思路前缀