abc0209 @ 2024-10-23 21:52:53
#include<bits/stdc++.h>
using namespace std;
long long n,p,a[5000007],d[5000007],x,y,z,minx=0x7f7f7f7f;
int main()
{
cin>>n>>p;
for(long long q=1;q<=n;q++)
{
cin>>a[q]; d[q]=a[q]-a[q-1];
}
while(p--)
{
cin>>x>>y>>z;
d[x]+=z; a[y+1]-=z;
}
for(long long q=1;q<=n;q++)
{
a[q]=a[q-1]+d[q];
minx=min(minx,a[q]);
}
cout<<minx<<endl;
return 0;
}
~~求求大佬找找错误 ~~
by hydk2012 @ 2024-10-23 21:59:16
能先解释一下代码吗
by hydk2012 @ 2024-10-23 22:02:10
18,19行只用一个ans累加和就可以了
by hydk2012 @ 2024-10-23 22:02:38
使用一个sum,说错了
by hydk2012 @ 2024-10-23 22:02:57
然后再用ans取最小值
by hydk2012 @ 2024-10-23 22:03:24
可以对比一下我的代码
#include<bits/stdc++.h>
using namespace std;
#define word return
#define from 0
#define hydk2012 ;
int n,p,a[5000005],c[5000005];
int main()
{
cin>>n>>p;
for(int i=1;i<=n;i++)
{
cin>>a[i];
c[i]=a[i]-a[i-1];
}
for(int i=1,x,y,z;i<=p;i++)
{
cin>>x>>y>>z;
c[x]+=z;
c[y+1]-=z;
}
int ans=1e9,sum=0;
for(int i=1;i<=n;i++)
{
sum+=c[i];
ans=min(ans,sum);
}
cout<<ans;
word from hydk2012
}
by hydk2012 @ 2024-10-23 22:03:43
求关谢谢
by hydk2012 @ 2024-10-23 22:03:56
@abc0209
by hydk2012 @ 2024-10-23 22:04:43
大部分都是对的了
by abc0209 @ 2024-10-23 22:30:32
@hydk2012 谢谢,已经ac了
by abc0209 @ 2024-10-23 22:31:41
@hydk2012 关了,谢谢