跳到正文

题解

P8755 [蓝桥杯 2021 省 AB2] 负载均衡

yuhaosheng约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年3月19日
更新
2026年3月19日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200009;
int n,m;
int a,b,c,d;
int v[N];
struct work{
	int endtime,d;
	bool operator<(const work &a) const{
		return endtime>a.endtime;
	}
};
priority_queue<work>q[N];
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>v[i];
	}
	while(m--){
		cin>>a>>b>>c>>d;
		while(!q[b].empty()&&q[b].top().endtime<=a){
			v[b]+=q[b].top().d;
			q[b].pop();
		}
		if(v[b]<d){
			cout<<"-1"<<endl;
		}
		else{
			q[b].push({a+c,d});
			v[b]-=d;
			cout<<v[b]<<endl;
		}
	}
	return 0;
}
原文