CF 280C. Vanya and Exams(div2)

来源:互联网 发布:jquery 1.10.2.min.js 编辑:程序博客网 时间:2024/06/06 02:53
http://codeforces.com/contest/492/problem/C

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?≤?1051?≤?r?≤?1091?≤?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?≤?r1?≤?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.


排序贪心就好了

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#include <stack>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;

using namespace std;
struct node
{
int a,b;
}nod[100002];
bool cmp(node x,node y){
return x.b<y.b;
}
ll n,r,avg,d;
ll k;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
cin>>n>>r>>avg;
ll sum=0;
for(int i=1;i<=n;i++)
{
scanf("%d %d",&nod[i].a,&nod[i].b);
sum+=nod[i].a;
}
d=n*avg-sum;
if(d<=0)cout<<0<<endl;
else
{
ll sum2=0;
sort(nod+1,nod+1+n,cmp);
for(int i=1;i<=n;i++)
{
if(r>nod[i].a)
{
k=r-nod[i].a;
if(k>d)
{
sum2+=d*nod[i].b;break;
}
else
{
sum2+=k*nod[i].b;d-=k;
}
}
}
cout<<sum2<<endl;
}
return 0;
}


0 0
原创粉丝点击