当根都<0,就不行了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG
#ifdef ON_DEBUG
#define D_e_Line printf("
----------
")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin);
#else
#define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#endif
struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std;
const int N = 1000007;
int a[N];
long long t[N << 2], tag[N << 2];
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
inline void Pushup(int rt){
t[rt] = Min(t[rt << 1], t[rt << 1 | 1]);
}
inline void Pushdown(int rt){
if(!tag[rt]) return;
t[rt << 1] -= tag[rt];
t[rt << 1 | 1] -= tag[rt];
tag[rt << 1] += tag[rt];
tag[rt << 1 | 1] += tag[rt];
tag[rt] = 0;
}
inline void Build(int rt, int l, int r){
if(l == r){
io >> t[rt];
return;
}
int mid = (l + r) >> 1;
Build(lson), Build(rson);
Pushup(rt);
}
inline void Updata(int rt, int l, int r, int L, int R, int w){
if(L <= l && r <= R){
t[rt] -= w;
tag[rt] += w;
return;
}
Pushdown(rt);
int mid = (l + r) >> 1;
if(L <= mid) Updata(lson, L, R, w);
if(R > mid) Updata(rson, L, R, w);
Pushup(rt);
}
inline int Query(int rt, int l, int r, int L, int R){
if(L <= l && r <= R){
return t[rt];
}
Pushdown(rt);
int mid = (l + r) >> 1, minn = 2147483647;
if(L <= mid) minn = min(minn, Query(lson, L, R));
if(R > mid) minn = min(minn, Query(rson, L, R));
return minn;
}
int main(){
//FileOpen();
int n, m;
io >> n >> m;
Build(1, 1, n);
R(i,1,m){
int w, l, r;
io >> w >> l >> r;
Updata(1, 1, n, l, r, w);
if(t[1] < 0){
printf("-1
%d
", i);
return 0;
}
}
printf("0");
return 0;
}