CF 280C. Vanya and Exams(div2)
来源:互联网 发布:jquery 1.10.2.min.js 编辑:程序博客网 时间:2024/06/06 02:53
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?
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).
In the first line print the minimum number of essays.
5 5 4
5 2
4 7
3 1
3 2
2 5
4
2 5 4
5 2
5 2
0
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<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#include <stack>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
struct node
{
int a,b;
}nod[100002];
bool cmp(node x,node y){
return x.b<y.b;
}
ll n,r,avg,d;
ll k;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
cin>>n>>r>>avg;
ll sum=0;
for(int i=1;i<=n;i++)
{
scanf("%d %d",&nod[i].a,&nod[i].b);
sum+=nod[i].a;
}
d=n*avg-sum;
if(d<=0)cout<<0<<endl;
else
{
ll sum2=0;
sort(nod+1,nod+1+n,cmp);
for(int i=1;i<=n;i++)
{
if(r>nod[i].a)
{
k=r-nod[i].a;
if(k>d)
{
sum2+=d*nod[i].b;break;
}
else
{
sum2+=k*nod[i].b;d-=k;
}
}
}
cout<<sum2<<endl;
}
return 0;
}
- CF 280C. Vanya and Exams(div2)
- C. Vanya and Exams
- CF 280A. Vanya and Cubes(div2)
- CF 280B. Vanya and Lanterns(div2)
- 492C - Vanya and Exams
- Codeforces Round #280 (Div. 2) C. Vanya and Exams
- Codeforces 492C Vanya and Exams(贪心)
- CodeForces 492C Vanya and Exams
- codeforce 492C. Vanya and Exams
- Codeforces-492C-Vanya and Exams
- Codeforces 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(贪心)
- CodeForces 492C Vanya and Exams(贪心)
- CF 552-C. Vanya and Scales
- cf 数制转换 C. Vanya and Scales
- CF 552 C. Vanya and Scales
- CF 253A. Anton and Letters
- CF 253B. Kolya and Tandem Repeat
- cust 学校选拔赛
- CF 280A. Vanya and Cubes(div2)
- CF 280B. Vanya and Lanterns(div2)
- CF 280C. Vanya and Exams(div2)
- C语言qsort的三种使用
- 升级chrome后字体模糊的解决办法
- 学生成绩管理系统(c++)控制台应用程序
- 控制台下画图
- 位运算
- 计算机中的负数
- 数据挖掘相关资料收集(持续更新)
- 面试题目