首页 > 试题广场 >

小苯的比赛上分

[编程题]小苯的比赛上分
  • 热度指数:2697 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}有一款著名的大型多人电子竞技游戏网站“喜爱福”,通常会举办一些比赛。选手通常只有一个账号,但一些人会“开小号”以提高最高分数。

\hspace{15pt}小苯是一名忠实玩家,他拥有 n 个账号,每个账号当前的分数为 a_i

\hspace{15pt}st****lk 的名言是:“只要你永远使用分数最低的账号参赛,那么你的 \max \mathrm{Rating} 将单调不降。”这里的 \max \mathrm{Rating} 指玩家所有账号中最高分的值。

\hspace{15pt}已知小苯会牢记此名言,并且在记录的 m 场比赛中,每次都使用当前分数最低的账号参赛。假设第 j 场比赛会让该账号分数增加 b_j,请你计算每场比赛结束后,小苯的 \max \mathrm{Rating}

输入描述:
\hspace{15pt}第一行输入两个正整数 n, m\left(1 \leqq n, m \leqq 10^5\right),分别表示账号数量和比赛场次。

\hspace{15pt}第二行输入 n 个整数 a_1, a_2, \dots, a_n\left(0 \leqq a_i \leqq 10^9\right),表示各账号初始分数。

\hspace{15pt}第三行输入 m 个整数 b_1, b_2, \dots, b_m\left(0 \leqq b_j \leqq 10^9\right),其中第 j 个数表示第 j 场比赛结束后账号分数的增加值。


输出描述:
\hspace{15pt}输出 m 行,第 j 行输出第 j 场比赛结束后,小苯的 \max \mathrm{Rating}
示例1

输入

5 6
1145 1500 1600 1538 1222
10 400 500 1000 2000 10000

输出

1600
1600
1722
2500
3538
11555

说明

共比赛了 6 场,每场结束后均输出小苯所有账号中的最高分。

初始分数最低的账号分数为 1145,第一场比赛后其分数变为 1145 + 10 = 1155,最高分依旧为 1600,故输出 1600。

第二场比赛使用当前最低分账号 1155 参赛,分数增加 400 变为 1555,最高分仍为 1600,故输出 1600。

第三场比赛使用当前最低分 1222 参赛,分数增加 500 变为 1722,此时最高分为 1722,故输出 1722。

以此类推,得到后续输出。
推荐
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    multiset<int> st;
    for(int i = 1, x; i <= n; i++) {
        cin >> x;
        st.emplace(x);
    }
    while(m -- ) {
        int x;
        cin >> x;
        int mn = *st.begin();
        st.erase(st.begin());
        st.emplace(mn + x);
        cout << *st.rbegin() << endl;
    }
}


signed main () {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int _ = 1;
    while(_ -- ) {
        solve();
    }
    return 0;
}

编辑于 2025-02-18 17:13:13 回复(0)
import sys, heapq

n, m = map(int, sys.stdin.readline().split())
a, b = list(map(int,sys.stdin.readline().split())), list(map(int,sys.stdin.readline().split()))
heapq.heapify(a)
max_a = max(a)
for j in b:
    min_a = heapq.heappop(a)
    min_a += j
    heapq.heappush(a, min_a)
    max_a = max(max_a, min_a)
    print(max_a)

发表于 2025-12-09 12:05:47 回复(0)
import heapq
import sys
n,m=map(int,input().split())
lst1=list(map(int,sys.stdin.readline().strip().split()))
lst2=list(map(int,sys.stdin.readline().strip().split()))
pq1=[]
pq2=[]
count=dict()
for i in lst1:
    heapq.heappush(pq1,i)
    heapq.heappush(pq2,-i)
    count[i]=count.get(i,0)+1
for i in lst2:
    x=0
    while pq1:
        x=pq1[0]
        if count.get(x,0)>0:
            count[x]-=1
            break
        else:
            heapq.heappop(pq1)
    heapq.heappush(pq1,x+i)
    count[x+i]=count.get(x+i,0)+1
    heapq.heappush(pq2,-(x+i))
    print(-pq2[0])




发表于 2025-10-08 17:52:43 回复(0)
import heapq

n, m = map(int, input().split())
li1 = list(map(int, input().split()))
minqueue = []
maxqueue = []
for i in li1:
    heapq.heappush(minqueue, i)
    heapq.heappush(maxqueue, -i)
li2 = list(map(int, input().split()))
max_val = heapq.heappop(maxqueue)
for i in range(m):
    min_val = heapq.heappop(minqueue)
    new_val = min_val + li2[i]
    heapq.heappush(minqueue, new_val)
    heapq.heappush(maxqueue, -new_val)
    current = maxqueue[0]
    if current < max_val:
        max_val = current
    print(-max_val)

发表于 2025-07-20 20:16:26 回复(0)