题意:有一个人有n门课程,每一门课程他最多获得r学分,他只要所有课程的平均学分有avg,他就可以获得奖学金,每门课程,他已经获得了ai学分,剩下的每一个学分,都需要写bi篇论文才能得到,然后问你,这个人最少写多少论文才能获得奖学金
思路:贪心,我们选择bi最小的开始写论文,然后扫一遍就好了,直到学分够为止
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
#define maxn 100005
pair<long long,long long> p[maxn];
int main()
{
int n;
long long r,avg;
scanf("%d%lld%lld",&n,&r,&avg);
avg*=n;
for(int i=0;i<n;i++)
{
scanf("%lld%lld",&p[i].second,&p[i].first);
avg-=p[i].second;
p[i].second = r - p[i].second;
}
sort(p,p+n);
long long ans = 0;
for(int i=0;i<n;i++)
{
if(avg<=0)break;
if(p[i].second>=avg)
{
ans+=avg*p[i].first;
break;
}
else
{
ans+=p[i].second*p[i].first;
avg-=p[i].second;
}
}
printf("%lld\n",ans);
}