zoukankan      html  css  js  c++  java
  • 6.10每日一题题解

    tokitsukaze and Soldier

    涉及知识点:

    • 优先队列

    solution:

    • (首先,我们看到这个题,肯定干第一反应就是结构体加排序,但是仔细读完题我们发现)
    • (第一,他有一个关于人数的限制的问题)
    • (第二,他需要我们找打最大的“战力值”)
    • (所以结构体加排序的方法是行不通的,那么我们怎么做呢)
    • (因为首先要满足所有选的人的s[i],所以我们肯定能想到用一种动态的方法来进行判断,这个方法就是优先队列)
    • (为什么用这个呢,因为优先队列即可以排序,也可以动态的保证人数问题,所以我们选用它)

    std:

    #include <bits/stdc++.h>
    using namespace std;
    //using namespace __gnu_pbds;
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef pair<ll,ll> pll;
    const int inf=0x7fffffff;
    const int N =5e5+10;
    const int maxn = 200010;
    ll n , k ;
    pll pr[100010];
    ll res =0 ;
    ll cmp(pair<int , int > a , pair < int , int >  b){
        return a.second > b.second;
    }
    priority_queue<ll , vector<ll >  , greater<ll > > qe;
    int main()
    {
        ios::sync_with_stdio(0);
        cin.tie(0), cout.tie(0);
        cin >>n;
        for(int i=0 ;i<n;i++){
        cin >>pr[i].first >> pr[i].second;
        }
        sort(pr,pr+n ,cmp);
        ll ma =0 ;ll sum =0 ;
        for(int i=0;i<n;i++){
            while(qe.size() >= pr[i].second){
                ma -= qe.top();
                qe.pop();
            }
            qe.push(pr[i].first);
            ma +=pr[i].first;
            sum = max(sum ,ma);
        }
        cout<<sum<<endl;
        return 0;
    }
    
  • 相关阅读:
    个税
    MC9S08中断机制
    各大公司面试笔试
    uc/OSII 任务切换
    Source Insight 使用
    充70送70
    兔年大年30
    pip更新后报No module named pip
    MsSql Md5
    iOS UIImage扩展方法(category):放大、旋转、合并UIImage、增加渐变层、添加阴影、调节透明度、保存到相册
  • 原文地址:https://www.cnblogs.com/QFNU-ACM/p/13089818.html
Copyright © 2011-2022 走看看