Blackox_xxx @ 2023-08-24 18:09:02
#include<iostream>
#include<algorithm>
using namespace std;
int n, p, a[5000005],s[5000005];
int main()
{
int minn = 1e9;
cin >> n >> p;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
s[i] = a[i] - s[i - 1];
}
for(int i = 1; i <= p; i++)
{
int x, y, z;
cin >> x >> y >>z;
s[x] += z;
s[y + 1] -= z;
}
for(int i = 1; i <= n; i++)
{
a[i] = a[i - 1] + s[i];
minn = min(minn,a[i]);
}
cout << minn;
return 0;
}
大佬们帮我看看哪里出错了,第一次手写的,和第一个题解差不多
by nightwatch.ryan @ 2023-08-24 18:15:26
@Iamchaier 你把cin>>a[i]
和s[i]=a[i]-s[i-1]
分成两个循环来写就可以AC了
by nightwatch.ryan @ 2023-08-24 18:26:28
#include<iostream>
#include<cmath>
#include<algorithm>
int a[5000010],b[5000010];
int main(){
int n,p;
std::cin>>n>>p;
for(int i=1;i<=n;i++){
std::cin>>a[i];
}
for(int i=1;i<=n;i++){
b[i]=a[i]-a[i-1];
}
int x,y,z;
for(int i=0;i<p;i++){
std::cin>>x>>y>>z;
b[x]+=z,b[y+1]-=z;
}
int minn=0x3f3f3f3f;
for(int i=1;i<=n;i++){
a[i]=a[i-1]+b[i];
minn=std::min(minn,a[i]);
}
std::cout<<minn;
}
by Blackox_xxx @ 2023-08-24 18:32:35
@nightwatch_ryan 感谢大佬指点!已经AC了记录