其他分享
首页 > 其他分享> > AcWing 125. 耍杂技的牛

AcWing 125. 耍杂技的牛

作者:互联网

//按照wi+si从小到大的顺序排,结果一定最优,最大的危险系数一定是最小的
//类比于国王游戏 
#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;
}

 

 

标签:PII,杂技,cow,int,res,sum,second,125,AcWing
来源: https://www.cnblogs.com/QingyuYYYYY/p/11914374.html