zoukankan      html  css  js  c++  java
  • 牛客 tokitsukaze and Soldier(优先队列+排序)

    对于忍受程度越高的人,程度越低的能够做到,程度更高的人也能做到,因此我们按程度从大到小排序后,用优先队列维护

    我们枚举每一天,将大于等于这天忍受程度都放进优先队列后,弹出小的直到满足要求

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+10;
    typedef long long ll;
    typedef pair<ll,ll> pll;
    pll g[N];
    int main(){
        ios::sync_with_stdio(false);
        int n;
        cin>>n;
        int i;
        for(i=0;i<n;i++){
            cin>>g[i].second;
            cin>>g[i].first;
        }
        sort(g,g+n);
        reverse(g,g+n);
        priority_queue<int,vector<int>,greater<int>> q;
        int j;
        ll sum=0;
        ll ans=0;
        for(i=n,j=0;i>=0;i--){
            while(j<n&&g[j].first>=i){
                q.push(g[j].second);
                sum+=g[j].second;
                j++;
            }
            while((int)q.size()>i){
                auto t=q.top();
                q.pop();
                sum-=t;
            }
            ans=max(ans,sum);
        }
        cout<<ans<<endl;
    }
    View Code
    没有人不辛苦,只有人不喊疼
  • 相关阅读:
    指针、字符串、数组操作
    字符串转换为数字(str2int)
    新的,开始。
    Hello, World.
    Go语言趣学指南lesson1
    hdoj2058
    poj2378
    hdoj1233
    poj2398
    hdoj1392
  • 原文地址:https://www.cnblogs.com/ctyakwf/p/13725806.html
Copyright © 2011-2022 走看看