仙风道骨 @ 2019-01-30 09:14:25
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,p,x,y,z;
int a[5000005]={0};
int b[5000005];
scanf("%d%d",&n,&p);
for(int i=1;i<n+1;i++)
scanf("%d",&a[i]);
for(int t=1;t<n+1;t++)
b[t]=a[t]-a[t-1];//差分
for(int k=0;k<p;k++){
scanf("%d",&x);
scanf("%d",&y);
scanf("%d",&z);
b[x]=z+b[x];
b[y+1]=z+b[y+1];
}
for(int v=1;v<n+1;v++){
a[v]=b[v]+a[v-1];
}
sort(a+1,a+n+1);//排序求最小值,因为a[0]是0,不考虑
printf("%d",a[1]);
// system("pause");
return 0;}
希望各位大神看看我错在哪里了( ๑ŏ ﹏ ŏ๑ )
by Three_Soil @ 2019-08-07 21:40:30
查分要倒着-
by 天外来客 @ 2021-05-21 20:46:51
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,p,a[5000005]={0},b[5000005],mini=1e9;
scanf("%d%d",&n,&p);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
b[i]=a[i]-a[i-1];
}
for(int i=0;i<=p;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
b[x]+=z;
//b[y+1]=z+b[y+1];(´íÎó)
b[y+1]-=z;//ÒѸÄÕý
}
for(int i=1;i<=n;i++){
a[i]=a[i-1]+b[i];
//Çómini£¨×îµÍ·Ö£©.
mini=min(mini,a[i]);
}
printf("%d",mini);
return 0;
}
by 天外来客 @ 2021-05-21 20:47:27
@仙风道骨