anya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade ai for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write biessays. He can raise the exam grade multiple times.
What is the minimum number of essays that Vanya needs to write to get scholarship?
Input
The first line contains three integers n, r, avg (1 ≤ n ≤ 105, 1 ≤ r ≤ 109, 1 ≤ avg ≤ min(r, 106)) — the number of exams, the maximum grade and the required grade point average, respectively.
Each of the following n lines contains space-separated integers ai and bi (1 ≤ ai ≤ r, 1 ≤ bi ≤ 106).
Output
In the first line print the minimum number of essays.
Example
Input
5 5 4
5 2
4 7
3 1
3 2
2 5
Output
4
Input
2 5 4
5 2
5 2
Output
0
Note
In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point.
In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
按所需的论文数按从小到大排序,注意所需学分是否满足,学分够了之后退出
#include<iostream>
#include<string.h>
#include<algorithm>
#include<cmath>
using namespace std;
struct node{
int x, y;
};
node s[100005];
bool cmp(node &a, node &b)
{
return a.y < b.y;
}
int main()
{
long long n, r, avg, k, sum, ans;
while(cin>>n>>r>>avg){
sum = ans = 0;
for(int i = 0; i < n; i++){
cin>>s[i].x>>s[i].y;
sum += s[i].x;
}
sort(s, s + n, cmp);
k = avg * n - sum;
if(k <= 0){
cout<<0<<endl;
return 0;
}
for(int i = 0; i < n && k > 0; i++){
if(k <= (r - s[i].x)){
ans += (k * s[i].y);
k = 0;
}
else{
ans += ((r - s[i].x) * s[i].y);
k -= (r - s[i].x);
}
}
cout<<ans<<endl;
}
return 0;
}