毕业考试

(exam.cpp/c/pas)

(1s/256M)

问题描述

快毕业了,Barry希望能通过期末的N门考试来顺利毕业。如果他的N门考试平均分能够达到V分,则他能够成功毕业。现在已知每门的分数不能够超过R;他的第i门考试目前得分为Ai,如果想要在这门科目增加一分则需要多写Bi篇论文。Barry想知道,如果想要毕业的话,他最少需要写多少篇论文?

 

输入格式(exam.in)

第一行三个整数,N, R, V,分别代表考试科目数,每门考试的最高分,需要达到的平均分。

接下来的N行每行两个整数A, B,分别代表这门考试的目前得分与增加一分需要多写的论文数。

 

输出格式(exam.out)

一个整数,代表他要毕业最少需要写的论文数。

 

样例输入

5 5 4

3 1

3 2

5 2

4 7

2 5

 

样例输出

4

 

数据范围及约束

对于30%的数据,N<=5, R<=3;

对于100%的数据,N<=100,000, R<=1000,000,000, 1<=V<=R

保证答案不超过10^18.

 

#include<cstdio>
#include<algorithm>
using namespace std;
int n,r,v;
long long tot,tmp,ans;
struct node
{
    int now,more;
    bool operator < (node p) const
    {
        return more<p.more;
    } 
}e[100001];
void out(long long x)
{
    if(x/10) out(x/10);
    putchar(x%10+'0');
}
void read(int &x)
{
    x=0; int f=1; char c=getchar();
    while(c<'0'|| c>'9') { if(c=='-') f=-1; c=getchar(); }
    while(c>='0' && c<='9')  { x=x*10+c-'0'; c=getchar(); }
    x*=f;
}
int main()
{
    freopen("exam.in","r",stdin);
    freopen("exam.out","w",stdout);
    read(n); read(r); read(v);
    for(int i=1;i<=n;i++) read(e[i].now),read(e[i].more),tmp+=e[i].now ;
    sort(e+1,e+n+1);
    tot=1ll*v*n;
    int i=1;
    while(tmp!=tot)
    {
        if(r-e[i].now+tmp<=tot) tmp+=(r-e[i].now),ans+=1ll*(r-e[i].now)*e[i].more;
        else ans+=1ll*(tot-tmp)*e[i].more,tmp=tot;
        i++;
    }
    out(ans);
}
View Code

相关文章: