题解 | 小苯的比赛上分

小苯的比赛上分

https://www.nowcoder.com/practice/f5c52183dfb148489321f881239216c1?tpId=383&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3FquestionJobId%3D10%26subTabName%3Donline_coding_page

#include <bits/stdc++.h>
#include <queue>
#include <vector>
using namespace std;

int main() {
    int n,m;
    cin >> n >> m;
    priority_queue<long long, vector<long long>, greater<long long> > z账号初始分;    
    vector<long long> b比赛增加值;
    long long max = -1;                         // 记录最大值(比赛结束后的多个号中最大分数)
    while(n){
        long long t;
        cin >> t;
        if(t > max ){
            max = t;
        }
        z账号初始分.push(t);
        n--;
    }
    while(m){
        long long t;
        cin >> t;
        b比赛增加值.push_back(t);
        m--;    
    }
    for(int i=0;i<b比赛增加值.size();i++){
        int t = 0;
        t = z账号初始分.top() + b比赛增加值[i];
        if(t > max){
            max = t;
        }
        z账号初始分.pop();
        z账号初始分.push(t);
        cout << max << endl;
    }
}
// 64 位输出请用 printf("%lld")

找最大值倒还容易,直接搞个值一次一次比就行,小顶堆顶上自动是每次最小值直接top即可

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务