/*
贪心算法: 按照祝福值从小到大排列
*/
#include <stdio.h>
#include <algorithm>
using namespace std;
struct grand {
int ai;
int bi;
bool operator < (const grand &A) const { //重载运算符,可用sort函数将按从小到大排列
return bi < A.bi;
}
}buf[100001];
int main() {
int n,r,avg;
while(scanf("%d%d%d",&n,&r,&avg) != EOF) {
//输入行数,科满分,平均分,
for(int i =0; i<n; i++)
scanf("%d%d",&buf[i].ai, &buf[i].bi);
sort(buf,buf+n); //按照祝福值排序
int sum =0;
for(int j =0; j<n; j++) {
sum += buf[j].ai;
}
int cha = n * avg - sum; //差平均分几分
int cnt =0; //统计祝福值
for(int i =0; i<n; i++) {
int f = r - buf[i].ai; //离科满分差几分
if(cha > f) {
cnt = cnt + f* buf[i].bi;
cha -= f;
} else {
cnt = cnt + cha * buf[i].bi;
cha =0;
break;
}
}
printf("%d\n",cnt);
}
return 0;
}
输出最少花费的祝福值
猜你喜欢
转载自blog.csdn.net/ivolcano/article/details/77417724
今日推荐
周排行