毕业考试

这里写图片描述
这里写图片描述
妥妥的贪心,将花费升序排列,直接模拟即可!
注意要开long long

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
long long n,r,v;
struct tw{
    long long s;
    long long r;
}a[100100];
int comp(const tw&x,const tw&y)
{
    return x.r<y.r;
}
int main()
{
    freopen("exam.in","r",stdin);
    freopen("exam.out","w",stdout);
    scanf("%lld%lld%lld",&n,&r,&v);

    long long tot=0;
    long long ans=0;
    v*=n;
    for(int i=1;i<=n;i++)
    scanf("%lld%lld",&a[i].s,&a[i].r),tot+=a[i].s;
    tot=v-tot;
    sort(a+1,a+n+1,comp);

    long long i=1;

    while(1)
    {
        if(a[i].s<r)
         {
            int tmp=r-a[i].s;
            if(tot>tmp)
             {
                ans+=(a[i].r*tmp);
                tot-=tmp;
                i++;
                continue;
             }
             if(tot==tmp)
             {
                ans+=a[i].r*tmp;
                break;
             }
             if(tot<tmp)
             {
                ans+=tot*a[i].r;
                break;
             }
         }
         else i++;
    }

    printf("%lld",ans);

    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值