很好的一道模拟题
#include<bits/stdc++.h>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int maxn = 2e5+5;
int n,m;
int s[maxn];
priority_queue<PII, vector<PII>, greater<PII> > q[maxn];
int main()
{
// freopen("1.in","r",stdin);
// freopen("1.txt","w",stdout);
scanf("%d%d",&n,&m);
for (int i=1; i<=n; i++) scanf("%d",&s[i]);
for (int i=1; i<=m; i++){
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
while(q[b].size() && q[b].top().first<=a){
s[b]+=q[b].top().second;
q[b].pop();
}
if (s[b]<d) printf("-1\n");
else{
q[b].push({a+c,d});
s[b]-=d;
printf("%d\n",s[b]);
}
}
return 0;
}