zombiell810975 @ 2024-03-05 19:02:57
此为ac代码,请留意注释处循环。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sco[5000006],der[5000006],a[5000006],n,k,i,j,l,r,add0,min00=1e9;
int main(){
cin>>n>>k;
for(i=1;i<=n;i++){
cin>>sco[i];
der[i]=sco[i]-sco[i-1];
}
for(i=1;i<=k;i++){
cin>>l>>r>>add0;
der[l]+=add0;
der[r+1]-=add0;
}
for(i=1;i<=n;i++){//此处循环条件为i<=n
a[i]=a[i-1]+der[i];
min00=min(min00,a[i]);
}
cout<<min00;
return 0;
}
而已下为错误代码,同样请注意注释。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sco[5000006],der[5000006],a[5000006],n,k,i,j,l,r,add0,min00=1e9;
int main(){
cin>>n>>k;
for(i=1;i<=n;i++){
cin>>sco[i];
der[i]=sco[i]-sco[i-1];
}
for(i=1;i<=k;i++){
cin>>l>>r>>add0;
der[l]+=add0;
der[r+1]-=add0;
}
for(i=1;i<=k;i++){//此时i<=n变味了i<=n
a[i]=a[i-1]+der[i];
min00=min(min00,a[i]);
}
cout<<min00;
return 0;
}
然鹅仅仅wa了一个点#2.....
蒟蒻震惊
by _Steve_ @ 2024-03-05 19:17:42
@zombiell810975 没过就行
by QWQ_123 @ 2024-03-05 19:22:22
@zombiell810975 所以可以将
by zombiell810975 @ 2024-03-05 19:30:46
尴尬的第二个注释打错了,是i<=n变为了i<=k(i<=p).
by laugh_001 @ 2024-03-05 23:52:22
@zombiell810975 ```cpp
using namespace std;
int n,p; int x,y,z; int a[100005],s[100005];
int read(){ int f=1,k=0; char c=getchar(); while(c<'0'||c>'9'){ if(c == '-') f=-1; c=getchar(); } while(c>='0'&&c<='9'){ k = k 10 + c-'0'; c=getchar(); } return fk; }
int main(){
n=read();
p=read();
for(int i=1;i<=n;i++){
a[i]=read();
s[i]=a[i]-a[i-1];
}
for(int i=1;i<=p;i++){
x=read(),y=read(),z=read();
s[x]+=z;
s[y+1]-=z;
}
int t=s[1],res=s[1];
for(int i=2;i<=n;i++){
t+=s[i];
res=min(t,res);
}
cout<<res;
return 0;
}
不知道哪有错误,如果大佬有时间的话,帮帮——,谢谢佬
by wangyiyao__ @ 2024-07-30 20:47:40
@laugh_001 希望更丰富的展现?使用 Markdown、KaTeX。