D - 淡黄的长裙

贪心题

题面的意思就是 ai bi
举个例子吧 比如a1 b1 a2 b2
处罚时间就是 ti-bi (ti是ai的和)
我们要使得 处罚时间的最大值最小
继续举例 吧 (b1<b2)
1 a1 b1 a2 b2
2 a2 b2 a1 b1
t1=max(a1-b1,a1+a2-b2)
t2=max(a2-b2,a1+a2-b1)
b1<b2
t2=a1+a2-b1
很明显 t1<t2
所以 我们只要吧 b大的放后面 排序一下即可

代码如下:

//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define fo1(a,b) for(int a=0;a<b;++a)
#define fo2(a,b) for(int a=1;a<=b;++a)
#define lowbit(a) a&(-a)
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=1e5+5;
const int mod=1e9+7;
struct node{
    int l,r;
    bool operator <(const node b) const{return r<b.r;}
}num[maxn];
int main()
{
    int t,n;
    cin>>t;
    fo2(k,t){
        cin>>n;
        fo2(i,n)
        scanf("%d%d",&num[i].l,&num[i].r);
        sort(num+1,num+1+n);
        ll ans=0,sum=0;
        fo2(i,n){
            sum+=num[i].l;
            if(ans<sum-num[i].r)
                ans=sum-num[i].r;
        }
        printf("Case %d: %lld\n",k,ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值