题目链接
题意:告诉你某人有n们课程,每一门的课程有分数上限r,以达到及平均分avg,才能拿奖学金,然后给出每门课当前的得分ai,以及如果你写bi篇文章的话,会使你的该们课程的分数提升一点,。
解法:贪心,按照bi小的开始贪心的选择。
#define CF
#ifndef CF
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<set>
#include<vector>
#else
#include<bits/stdc++.h>
#endif // CF
using namespace std;
#define LL long long
#define pb push_back
#define X first
#define Y second
#define cl(a,b) memset(a,b,sizeof(a))
typedef pair<long long ,long long > P;
const int maxn=100005;
const LL inf=1LL<<60;
const LL mod=1e9+7;
struct node{
LL a,b;
bool operator<(const node &t)const {
return b<t.b;
}
}p[maxn];
int main(){
LL n,r,avg;
scanf("%lld%lld%lld",&n,&r,&avg);
LL sum=0;avg*=n;
for(int i=0;i<n;i++){
scanf("%lld%lld",&p[i].a,&p[i].b);
sum+=p[i].a;
}
if(sum>=avg){
return puts("0");
}
sort(p,p+n);
LL ans=0;
for(int i=0;i<n;i++){
if(p[i].a<r){
int need=min(r-p[i].a,avg-sum);
if(need<=0)break;
sum+=need;
ans+=need*p[i].b;
}
}
printf("%lld\n",ans);
return 0;
}