https://vjudge.net/problem/CodeForces-492C
题目不介绍了,测试数据也有问题,用int试了好久没过去
吃一堑 涨一智
using namespace std;
typedef long long LL;
const int maxn = 1e5+10;
struct P {
LL x, y;
P(LL x = 0, LL y = 0): x(x), y(y) {}
}p[maxn];
inline bool cmp (const P p1, const P p2) {
return p1.y < p2.y;
}
int main() {
LL n, r, aver;
cin >> n >> r >> aver;
LL x, y, grade = aver * n;
for(int i = 0; i < n; i++) {
cin >> x >> y;
grade -= x;
p[i] = P(r-x, y);
}
sort(p, p+n, cmp);
LL ans = 0;
for(int i = 0; i < n; i++) {
if(grade <= 0) break;
if(p[i].x < grade) {
ans += p[i].x * p[i].y;
grade -= p[i].x;
}
else {
ans += grade * p[i].y;
break;
}
}
printf("%lld\n", ans);
return 0;
}