题目:
样例输入:
3 2
1 1 1
1 2 1
2 3 1
样例输出:
2
代码:
#include<bits/stdc++.h>
using namespace std;long long sa[5000005];
long long sb[5000005];int main()
{int n,p;cin>>n>>p;for(int i=1;i<=n;i++){cin>>sa[i];}for(int i=1;i<=p;i++){int x,y,z;cin>>x>>y>>z;sb[x]+=z;sb[y+1]-=z;}int mina=9999999;for(int i=1;i<=n;i++){sb[i]+=sb[i-1];sa[i]+=sb[i];if(sa[i]<mina){mina=sa[i];}}cout<<mina<<endl;}