第一行输入两个正整数
,分别表示账号数量和比赛场次。
第二行输入
个整数
,表示各账号初始分数。
第三行输入
个整数
,其中第
个数表示第
场比赛结束后账号分数的增加值。
输出
行,第
行输出第
场比赛结束后,小苯的
。
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 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)
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;
}
} import heapq n, m = map(int, input().split()) scores = list(map(int, input().split())) changes = list(map(int, input().split())) max_rating = max(scores) heap = [(score, i) for i, score in enumerate(scores)] heapq.heapify(heap) for change in changes: min_score, min_index = heapq.heappop(heap) new_score = min_score + change scores[min_index] = new_score max_rating = max(max_rating, new_score) heapq.heappush(heap, (new_score, min_index)) print(max_rating)
#include <iostream>
using namespace std;
#include<set>
#include<vector>
int main() {
int n,m;
cin>>n>>m;
multiset<int>s;
vector<int>v;
while(n--){
int a;
cin>>a;
s.insert(a);
}
for(int i=0;i<m;i++){
int b;
cin>>b;
v.push_back(b);
}
for(int i=0;i<m;i++){
int now_use_score=(*s.begin());
int afterscore=now_use_score+v[i];
s.erase(s.begin());
s.insert(afterscore);
auto pos=s.end();
pos--;
cout<<(*pos)<<endl;
}
} 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])
#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;
}
} 找最大值很简单,直接一个一个算的时候找就行
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int N = 1e5+10;
int a[N],b[N];
int main()
{
cin>>n>>m;
for(int i=0;i<n;++i)cin>>a[i];
for(int j=0;j<m;++j)cin>>b[j];
priority_queue<int,vector<int>,greater<int> >pq;
int ma=-1;
for(int i=0;i<n;++i){
pq.push(a[i]);
ma=max(ma,a[i]);
}
for(int i=0;i<m;++i)
{
int t=pq.top();
pq.pop();
t+=b[i];
ma=max(ma,t);
pq.push(t);
cout<<ma<<'\n';
}
return 0;
} import java.util.PriorityQueue;
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int accounts = in.nextInt();
int plays = in.nextInt();
int max_ = 0;
int[] playsArray = new int[plays];
PriorityQueue<Integer> pq = new PriorityQueue<>();
for(int i = 0; i < accounts; i++){
int rating = in.nextInt();
max_ = Math.max(max_, rating);
pq.offer(rating);
}
for(int i = 0; i < plays; i++) playsArray[i] = in.nextInt();
for(int i = 0; i < plays; i++){
int now = pq.poll();
now += playsArray[i];
max_ = Math.max(max_, now);
pq.offer(now);
System.out.println(max_);
}
}
} priority_queue<int, vector<int>, greater<int>> minheap;
#include <functional>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int minium_pos(vector<int>& ivc) {
int min = 0;
for (int i = 0; i < ivc.size(); i++) {
if (ivc[i] < ivc[min])
min = i;
}
return min;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> account(n);
for (int& x : account) {
cin >> x;
}
vector<int> changes(m);
for (int& x : changes) {
cin >> x;
}
int min = 0, max_value = 0;
priority_queue<int, vector<int>, greater<int>> minheap;
for (int i = 0; i < n; i++) {
minheap.push(account[i]);
if (account[i] > max_value)
max_value = account[i];
}
for (int i = 0; i < changes.size(); i++)
{
int new_min = minheap.top() + changes[i];
if(new_min > max_value)
max_value = new_min;
minheap.pop();
minheap.push(new_min);
cout << max_value << endl;
}
}
#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; }