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.
题意:Vanya修了n门课,第i门课的学分是ai,已知每门课的最高学分不能超过r,而且他想得奖学金,但是获得奖学金的要求是:他的所有课的平均学分不得低于avg,如果不满足的话,他就不得不写论文去增加自己的学分,已知第i门课要增加1学分的话,必须写bi篇论文,由于,他比较懒, 所以让你计算最少他需要写多少篇论文才能获得奖学金。
#include <algorithm>
using namespace std;
{
int a;
int b;
};
int main()
{
long long n,r,avg,sum = 0;
long long sum_poet = 0;
int i;
scanf("%I64d %I64d %I64d",&n,&r,&avg);
for(i = 0; i < n; i++)
{
scanf("%d %d",&num[i].a,&num[i].b);
sum += num[i].a;
}
sort(num,num + n,cmp);
int flag = 0;
i = 0;
for(int i = 0;i < n&&sum < avg * n;i++)
{
flag = 1;
long long int t = min(avg * n - sum,r - num[i].a);
sum += t;
sum_poet += t * num[i].b;
}
if(flag)
printf("%I64d\n",sum_poet);
else
printf("0\n");
return 0;
}
{
return x.b < y.b;
}