C. Vanya and Exams
2015-01-05 09:14
302 查看
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vanya 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 bi essays.
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.
Sample test(s)
input
output
input
output
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<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
int main()
{
long long n,r,avr,s=0,x=0; cin>>n>>r>>avr;
pair <long long, long long> a[100005];
for(int i=0;i<n;i++)
{
cin>>a[i].second>>a[i].first;
s+=a[i].second;
}
x=n*avr-s;
if (x<=0)
{
cout<<0;
return 0;
}
sort(a,a+n);
long long ans=0;
for(int i=0;i<n;i++)
{
long long kol=min(x, r-a[i].second);
x-=kol;
ans+=kol*a[i].first;
if (x==0)
{
break;
}
}
cout<<ans<<endl;
return 0;
}
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vanya 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 bi essays.
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.
Sample test(s)
input
5 5 4 5 2 4 7 3 1 3 2 2 5
output
4
input
2 5 45 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<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
int main()
{
long long n,r,avr,s=0,x=0; cin>>n>>r>>avr;
pair <long long, long long> a[100005];
for(int i=0;i<n;i++)
{
cin>>a[i].second>>a[i].first;
s+=a[i].second;
}
x=n*avr-s;
if (x<=0)
{
cout<<0;
return 0;
}
sort(a,a+n);
long long ans=0;
for(int i=0;i<n;i++)
{
long long kol=min(x, r-a[i].second);
x-=kol;
ans+=kol*a[i].first;
if (x==0)
{
break;
}
}
cout<<ans<<endl;
return 0;
}
相关文章推荐
- Codeforces Round #280 (Div. 2)_C. Vanya and Exams
- Codeforces Round #280 (Div. 2)_C. Vanya and Exams
- Codeforces-492C-Vanya and Exams
- Codeforces 492C Vanya and Exams【贪心】
- CodeForces 492C Vanya and Exams(贪心)
- 492C - Vanya and Exams
- Vanya and Exams
- Codeforces Round #280 (Div. 2) C. Vanya and Exams
- Codeforces Round #280 (Div. 2)C. Vanya and Exams(贪心)
- Vanya and Exams
- Vanya and Exams
- CF 280C. Vanya and Exams(div2)
- C. Vanya and Examsv
- Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心
- Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心
- Codeforces Round #355 (Div. 2) D. Vanya and Treasure
- codeforces——677A——Vanya and Fence
- 暴力/进制转换 Codeforces Round #308 (Div. 2) C. Vanya and Scales
- #308 (div.2) A. Vanya and Table
- cf 数制转换 C. Vanya and Scales