题解 | 小苯的比赛上分

小苯的比赛上分

https://www.nowcoder.com/practice/f5c52183dfb148489321f881239216c1

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,x,y,max=0;
    cin>>n>>m;
    priority_queue<int,vector<int>,greater<>> s;
    for(int i=0;i<n;i++){
        cin>>x;
        if(x>max)
        max=x;
        s.push(x);
    }
    while(m--){
        cin>>x;    
        y=s.top()+x;
        if(y>max)
        max=y;
        s.pop();
        s.push(y);
        cout<<max<<'\n';
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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