#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 1000010
int n,m,r[N],d[N],s[N],t[N];
int sum[N];
int read ()
{
int s=0,k=1;char c=getchar ();
while (!isdigit (c)) {if (c=='-') k=-1;c=getchar ();}
while (isdigit (c)) {s=s*10+c-'0';c=getchar ();}
return k*s;
}
void Init ()
{
n=read (),m=read ();
for (int i=1;i<=n;i++)
r[i]=read ();
for (int i=1;i<=m;i++)
d[i]=read (),s[i]=read (),t[i]=read ();
}
bool check (int x)
{
memset (sum,0,sizeof (sum));
for (int i=1;i<=x;i++)
{
sum[s[i]]+=d[i];
sum[t[i]+1]-=d[i];
}
for (int i=1;i<=n;i++)
{
sum[i]+=sum[i-1];
if (sum[i]>r[i])
return false;
}
return true;
}
void Work ()
{
int L=0,R=m,mid;
while (L<R)
{
int mid=(L+R)>>1;
if (check (mid)) L=mid;
else R=mid-1;
}
if (mid==n) puts ("0");
else
{
puts ("-1");
printf ("%d\n",L+1);
}
}
int main ()
{
Init ();
Work ();
return 0;
}
为什么超时