其他分享
首页 > 其他分享> > NC50439 tokitsukaze and Soldier

NC50439 tokitsukaze and Soldier

作者:互联网

题目

1.题目大意

2.题目分析

3.题目代码

#include<bits/stdc++.h>

using namespace std;

typedef struct so{
    int v, s;
}so;

bool cmp(so a, so b){
    if(a.s==b.s)return a.v>b.v;
    return a.s>b.s;
}

int main() {
    int n;
    cin >> n;
    so ss[n];
    for(int i=0;i<n;i++) cin >> ss[i].v >> ss[i].s;
    sort(ss,ss+n,cmp);
    priority_queue<int, vector<int>, greater<int>> q;
    long long ans = 0, sum = 0;
    for(int i=0;i<n;i++){
        sum += ss[i].v;
        q.push(ss[i].v);
        while(q.size()>ss[i].s) sum -= q.top(), q.pop();
        ans = max(sum, ans);
    }
    cout << ans << endl;
}

标签:题目,tokitsukaze,ss,NC50439,Soldier,int,so,ans,sum
来源: https://www.cnblogs.com/zhangyi101/p/16634689.html