求助!

P1115 最大子段和

@[Bilion_冰凌帅](/space/show?uid=54372) **子段的最小长度为1。**
by ⚡小林孑⚡ @ 2019-02-08 19:56:55


@[zws666](/space/show?uid=119959) 但怎么改呀qaq
by A_Đark_Horcrux @ 2019-02-08 19:59:07


@[Bilion_冰凌帅](/space/show?uid=54372) ```qwq #include<iostream> using namespace std; int a,n,last,f[200005],ans=-1; int mx=-10001; int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a; f[i]=max(f[i-1]+a,0); ans=max(ans,f[i]); mx=max(a,mx); } if(ans<=0) cout<<mx; else cout<<ans; } ```
by ⚡小林孑⚡ @ 2019-02-08 20:08:07


@[zws666](/space/show?uid=119959) 谢谢大佬!
by A_Đark_Horcrux @ 2019-02-08 20:17:28


@[Bilion_冰凌帅](/space/show?uid=54372) fAKe我是蒟蒻
by ⚡小林孑⚡ @ 2019-02-08 20:30:24


@[Bilion_冰凌帅](/space/show?uid=54372) ```cpp #include<iostream> using namespace std; int main() { int n,tot=-9999999,ans=-9999999; cin>>n; int m[n+1]; for(int i=1;i<=n;i++)cin>>m[i]; for(int i=1;i<=n;i++) { tot=max(tot+m[i],m[i]); ans=max(ans,tot); } cout<<ans; return 0; } ``` 这样可以省一个max哦qwq
by WA鸭鸭 @ 2019-02-08 20:40:24


|