95分,求助!!!
#include<bits/stdc++.h>
#define M 1000005
using namespace std;
int n,m,a[M],d[M],s[M],t[M],pos[M];
bool pd(int x){
memset(pos,0,sizeof(pos));
for(int i=1;i<=x;++i){
pos[s[i]]-=d[i];pos[t[i]+1]+=d[i];
}
for(int i=1;i<=n;++i){
pos[i]+=pos[i-1];
if(pos[i]+a[i]<0)return 0;
}
return 1;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
cin>>n>>m;
for(int i=1;i<=n;++i)cin>>a[i];
for(int i=1;i<=m;++i)cin>>d[i]>>s[i]>>t[i];
int l=1,r=n;
while(l<r){
int mid=l+r>>1;
if(pd(mid))l=mid+1;
else r=mid;
}
if(l==m+1)cout<<0;
else {
cout<<"-1\n"<<l;
}
return 0;
}
谢谢大佬!!