#include <stdio.h> #include <algorithm> using std::sort; const int MAXN = 100100; int n, r, avg; struct Subject { int a, b; } subject[MAXN]; typedef long long LL; LL gap; void read() { int a, b; scanf("%d%d%d", &n, &r, &avg); for (int i = 0; i < n; ++i) { scanf("%d%d", &a, &b); gap += a; subject[i].a = a; subject[i].b = b; } gap = (LL)n * avg - gap; } bool lowestCost(const Subject& p, const Subject& q) { return p.b < q.b; } void work() { if (gap <= 0) { puts("0"); return; } LL res = 0; sort(subject, subject + n, lowestCost); for (int i = 0; i < n; ++i) { LL t = r - subject[i].a; if (t < gap) { res += t * subject[i].b; gap -= t; } else { res += gap * subject[i].b; gap = 0; break; } } printf("%lld\n", res); } int main() { read(); work(); return 0; }
点赞 1

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务