boolis_valid(int mid, int len){ memset(S, 0, sizeof(S)); S[1] = A[1]; for(int i=2;i<=len;i++){ S[i] = A[i]-A[i-1]; } for(int i=1;i<=mid;i++){ S[interval[i].l] -= interval[i].dat; S[interval[i].r+1] += interval[i].dat; } ll res = 0; for(int i=1;i<=len;i++){ res += S[i]; if (res<0)returntrue; } returnfalse; }
intsolve(int arr_len, int interval_len){ int l = 1, r = interval_len + 1; while(l<r){ int mid = (l+r)>>1; if(is_valid(mid, arr_len)){ r = mid; }else{ l = mid+1; } } if (l==interval_len+1)return0; return l; }
intmain(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>A[i]; } for(int i=1;i<=m;i++){ cin>>interval[i].dat>>interval[i].l>>interval[i].r; } int res = solve(n,m); if(res){ cout<<"-1\n"<<res<<endl; return0; } cout<<"0\n"; return0; }