显示代码纯文本
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=1000001;
int n,m,r[maxn],d[maxn],s[maxn],t[maxn],L,R,ans,i;
bool check(int now)
{
int x[maxn],sum=0;
memset(x,0,sizeof(x));
for(int j=1;j<=now;j++)
{
x[s[j]]+=d[j];
x[t[j]+1]-=d[j];
}
for(int j=1;j<=n;j++)
{
sum+=x[j];
if(sum>r[j])return 0;
}
return 1;
}
int Main()
{
freopen("classrooms.in","r",stdin);freopen("classrooms.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)scanf("%d",&r[i]);
for(i=1;i<=m;i++)scanf("%d%d%d",&d[i],&s[i],&t[i]);
L=1;R=m;
while(L<=R)
{
int mid=L+((R-L)>>1);
if(check(mid))L=mid+1;
else{ans=mid;R=mid-1;}
}
if(ans)printf("-1\n");
printf("%d\n",ans);
return 0;
}
int main(){;}
int syy=Main();