huangshaochen @ 2024-12-27 21:31:37
求大佬指教!80分代码,剩下20分没了!(QWQ)
#include <iostream>
using namespace std;
const int N=1e5+5;
int n,p,minn=1e9;
long long s[N],a[N];
int main(){
cin>>n>>p;
for(int i=1;i<=n;i++){
cin>>s[i];
}
for(int i=1;i<=n;i++){
a[i]=s[i]-s[i-1];
}
for(int i=1;i<=p;i++){
int l,r,x;
cin>>l>>r>>x;
a[l]+=x;
a[r+1]-=x;
}
for(int i=1;i<=n;i++){
s[i]=s[i-1]+a[i];
if(minn>s[i]){
minn=s[i];
}
}
cout<<minn;
return 0;
}
by Ziy119 @ 2024-12-27 21:42:21
试试这个,差不多但能过
#include<bits/stdc++.h>
using namespace std;
long long a[5000005],df[5000005],n,p;
int main(){
cin>>n>>p;
for(int i=1;i<=n;i++){
cin>>a[i];
}
while(p--){
int x,y,z;
cin>>x>>y>>z;
df[x]+=z,df[y+1]-=z;
}
long long sum=0,minn=1000000000;
for(int i=1;i<=n;i++){
sum+=df[i];
minn=min(minn,sum+a[i]);
}
cout<<minn;
return 0;
}
by huangshaochen @ 2024-12-28 21:40:34
谢谢大佬指教!