第一行输入两个正整数
,分别表示账号数量和比赛场次。
第二行输入
个整数
,表示各账号初始分数。
第三行输入
个整数
,其中第
个数表示第
场比赛结束后账号分数的增加值。
输出
行,第
行输出第
场比赛结束后,小苯的
。
5 6 1145 1500 1600 1538 1222 10 400 500 1000 2000 10000
1600 1600 1722 2500 3538 11555
共比赛了 6 场,每场结束后均输出小苯所有账号中的最高分。
初始分数最低的账号分数为 1145,第一场比赛后其分数变为,最高分依旧为 1600,故输出 1600。
第二场比赛使用当前最低分账号 1155 参赛,分数增加 400 变为 1555,最高分仍为 1600,故输出 1600。
第三场比赛使用当前最低分 1222 参赛,分数增加 500 变为 1722,此时最高分为 1722,故输出 1722。
以此类推,得到后续输出。
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
// 使用BufferedReader提高大输入效率
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] parts = br.readLine().split(" ");
int accountNum = Integer.parseInt(parts[0]);
int raceNum = Integer.parseInt(parts[1]);
TreeMap<Integer, Integer> tm = new TreeMap<>();
// 读取初始账号分数
parts = br.readLine().split(" ");
for (int i = 0; i < accountNum; i++) {
int score = Integer.parseInt(parts[i]);
tm.put(score, tm.getOrDefault(score, 0) + 1);
}
// 读取所有比赛的分数增加值
parts = br.readLine().split(" ");
for (int i = 0; i < raceNum; i++) {
int getRating = Integer.parseInt(parts[i]);
int minRating = tm.firstKey();
int minCount = tm.get(minRating);
if (minCount == 1) {
tm.remove(minRating);
} else {
tm.put(minRating, minCount - 1);
}
int newRating = minRating + getRating;
tm.put(newRating, tm.getOrDefault(newRating, 0) + 1);
System.out.println(tm.lastKey());
}
}
}
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
private static PriorityQueue<Integer> heap = new PriorityQueue<>();
private static int maxTating = Integer.MIN_VALUE;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
for(int i = 0 ; i < n ; i++){
int score = sc.nextInt();
maxTating = Math.max(maxTating,score);
heap.offer(score);
}
int[] match = new int[m];
for(int i = 0 ; i < m ; i++){
match[i] = sc.nextInt();
}
List<Integer> ans = resolve(match);
for(int max : ans){
System.out.println(max);
}
sc.close();
}
private static List<Integer> resolve(int[] match){
int m = match.length;
List<Integer> ans = new ArrayList<>(m);
for(int each : match){
int currentScore = heap.poll();
currentScore += each;
maxTating = Math.max(maxTating,currentScore);
ans.add(maxTating);
heap.offer(currentScore);
}
return ans;
}
}
#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; }