您好,欢迎来到百家汽车网。
搜索
您的当前位置:首页Acwing贪心 125.耍杂技的牛

Acwing贪心 125.耍杂技的牛

来源:百家汽车网

#include <iostream>
#include <algorithm>

using namespace std;

typedef pair<int, int> PII;

const int N = 50010;

int n;
PII cow[N];   

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i ++ )
    {
        int s, w;
        scanf("%d%d", &w, &s);
        cow[i] = {w + s, w};
    }
    //上面的减去我的耐受力
    //
    sort(cow, cow + n);   //固定了所有奶牛的叠加顺序
    
    int res = -2e9, sum = 0;
    for (int i = 0; i < n; i ++ )
    {
        int s = cow[i].first - cow[i].second, w = cow[i].second;
        res = max(res, sum - s);
        sum += w;
    }
    
    printf("%d\n", res);
    
    return 0;
}
/*

多数用数学办法推理公式

*/

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- baijiahaobaidu.com 版权所有 湘ICP备2023023988号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务