hqzx_610fuziyu @ 2024-10-27 21:34:15
#include<bits/stdc++.h>
using namespace std;
int a[500005],m,n;
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=m;i++)
{
int x,y,z;
cin>>x>>y>>z;
if(x>y)swap(x,y);
a[x]+=z;
a[y+1]-=z;
}
for(int i=1;i<=n;i++)
{
a[i]+=a[i-1];
}
sort(a+1,a+n+1);
cout<<a[1];
return 0;
}
by Besheep @ 2024-10-27 21:44:50
你没有对数组先进行差分处理 其次,数组开小了
by Besheep @ 2024-10-27 21:47:28
@hqzx_610fuziyu 求关qwq
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,p;
cin>>n>>p;
int a[n+10]={0},ch[n+10]={0};
for(int i=1;i<=n;i++){
cin>>a[i];
ch[i]=a[i]-a[i-1];
}
for(int i=1;i<=p;i++){
int x,y,z;
cin>>x>>y>>z;
ch[x]+=z;
ch[y+1]-=z;
}
for(int i=1;i<=n;i++){
ch[i]=ch[i-1]+ch[i];
}
int zx=INT_MAX;
for(int i=1;i<=n;i++){
zx=min(ch[i],zx);
}
cout<<zx;
return 0;
}
by hqzx_610fuziyu @ 2024-10-27 22:00:47
感谢大神的大恩大德,小弟无以为报, 只得关qwq
by hqzx_610fuziyu @ 2024-10-27 22:01:13
已AC