pjr_freopen @ 2024-09-25 23:27:58
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=5e6+5;
int a[N],d[N];
int main(){
memset(d,0,sizeof(d));
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
}
int h=-1;
while(m--){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
d[x]+=z;
d[y+1]-=z;
if(y>h)h=y;
}
for(int i=2;i<=h;++i){
d[i]+=d[i-1];
}
int ans=1<<30;
for(int i=1;i<=n;++i){
if(a[i]+d[i]<ans)ans=a[i]+d[i];
}
printf("%d\n",ans);
return 0;
}
by xujingbo @ 2024-09-25 23:42:59
初始化
d[i]=a[i]-a[i-1]