OTH_chinese_dragon @ 2024-06-01 11:39:25
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,z,a[1000000];
int main(){
cin >> n >> m;
for(int i=1; i<=n; i++){
cin >> a[i];
}
for(int i=1; i<=m; i++){
cin >> x >> y >> z;
for(int i=x; i<y; i++){
a[i]+=z;
}
}
int min=100000;
for(int i=1; i<=m; i++){
if(a[i] < min){
min=a[i];
}
}
cout<<min;
return 0;
}
求助60分,2,5点错误
by KY_ABC @ 2024-06-01 11:43:26
#include<bits/stdc++.h>
using namespace std;
int d[5000001],a[5000001];
int main(){
int n,p,x,y,z,i,min=10000010;
cin>>n>>p;
for(i=1;i<=n;i++){
cin>>a[i];
}
for(i=1;i<=n;i++){
d[i]=a[i]-a[i-1];
}
for(i=0;i<p;i++){
cin>>x>>y>>z;
d[x]+=z;
d[y+1]-=z;
}
for(i=1;i<=n;i++){
a[i]=a[i-1]+d[i];
if(min>a[i]){
min=a[i];
}
}
cout<<min;
return 0;
}
by Ice_rnfmabj @ 2024-06-01 12:51:57
@OTH_qianlong 要用差分
by Canton_ @ 2024-06-01 21:45:17
@KY_ABC 跟题解一模一样1
by OTH_chinese_dragon @ 2024-06-08 09:01:31
谢谢了,这困扰我好久了