比赛 欢乐五一练练练 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 借教室 最终得分 100
用户昵称 TARDIS 运行时间 1.233 s
代码语言 C++ 内存使用 13.57 MiB
提交时间 2017-04-28 16:26:46
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstring>
#include<deque>
#define itn int
#define coder goodboy
using namespace std;
typedef long long LL;typedef unsigned long long ULL;
const int maxn=1000010;
int n,m,room[maxn],cnt[maxn],l[maxn],r[maxn],d[maxn];
inline void in(){
	freopen("classrooms.in","r",stdin);
	freopen("classrooms.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
		scanf("%d",&room[i]);
	}
	for (int i=1;i<=m;i++){
		scanf("%d%d%d",&d[i],&l[i],&r[i]);
		cnt[l[i]]+=d[i];
		cnt[r[i]+1]-=d[i];
	}
}
inline void deal(){
	int c=m,ans=0;
	for (int i=1;i<=n;i++){
		ans+=cnt[i];
		while(c>=1&&ans>room[i]){
			if (i>=l[c]&&i<=r[c]) ans-=d[c];
			cnt[l[c]]-=d[c];
			cnt[r[c]+1]+=d[c];
			c--;
		}
	}
	if (c==m){
		printf("0\n");
	}
	else printf("-1\n%d",++c);
}
int Main(){
	in();
	deal();
	return 0;
}
int main(){;}
int goodboy=Main();