Ryoo @ 2024-10-29 18:08:39
#include <bits/stdc++.h>
using namespace std;
int a[5000005],b[5000005],cha[5000005];
int main() {
int n, p;
scanf("%d%d", &n, &p);
for(int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if(i == 1) cha[i] = a[i];
else cha[i] = a[i]-a[i-1];
}
for(int i = 1; i <= p; i++) {
int x,y,z;
scanf("%d%d%d", &x,&y,&z);
cha[x] += z;cha[y+1] += z;
}
int base = cha[1];
int tmp,minn;
for(int i = 1; i <= n; i++) {
if(i == 1) {tmp = base;minn = tmp;}
else{
tmp += cha[i];
if(tmp < minn) minn = tmp;
}
}
printf("%d", minn);
return 0;
}
by chenxitao @ 2024-10-29 18:17:24
#include<bits/stdc++.h>
using namespace std;
int b[5000010],a[5000010],n,p,x,y,z,m=1e9;
int main(){
cin>>n>>p;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)b[i]=a[i]-a[i-1];
for(int i=0;i<p;i++){
cin>>x>>y>>z;
b[x]+=z,b[y+1]-=z;
}
for(int i=1;i<=n;i++){
a[i]=a[i-1]+b[i];
if(m>a[i])m=a[i];
}
cout<<m;
return 0;
}
求关
by claoday @ 2024-10-29 18:32:04
你第 cha[y+1] += z
写错了,
应该为 cha[y+1] -= z
。
然后就
by Ryoo @ 2024-10-30 15:28:49
@chenxitao 感谢,已关
by Ryoo @ 2024-10-30 15:29:17
@claoday 感谢,已关