标签:
4 3
2 5 4 3
2 1 3
3 2 4
4 2 4
-1
2
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> using namespace std; const int maxn = 1050000; long long n,m,r[maxn],d[maxn],s[maxn],t[maxn],sum[maxn]; void input(){ cin>>n>>m; for(int i = 1;i <= n;i++) scanf("%lld",&r[i]); for(int i = 1;i <= m;i++) scanf("%lld%lld%lld",&d[i],&s[i],&t[i]); } bool check(int tg){ if(!tg) return true; memset(sum,0,sizeof(sum)); for(int i = 1;i <= tg;i++){ sum[s[i]] += d[i]; sum[t[i] + 1] -= d[i]; } long long add = 0; for(int i = 1;i <= n;i++){ add += sum[i]; if(add > r[i]) return false; } return true; } void div(){ int lans = 0,rans = m,mans; while(lans <= rans){ mans = (lans + rans) >> 1; if(check(mans)){ lans = mans + 1; }else{ rans = mans - 1; } } if(!check(mans)) mans--; if(mans == m) cout<<0; else{ cout<<-1<<endl<<mans+1; } return; } int main(){ input(); div(); return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5655969.html