提交时间:2021-05-27 20:16:26

运行 ID: 19975

#include<iostream> using namespace std; int main() { // freopen("x14_6.in","r",stdin); // freopen("x14_6.out","w",stdout); int i,n,ans,dp[100],a[100]; cin>>n; for(i=1;i<=n;i++) cin>>a[i]; dp[1]=a[1]; ans=a[1]; for(i=2;i<=n;++i){ if(a[i]<=dp[i-1]+a[i]) dp[i]=dp[i-1]+a[i]; else dp[i]=a[i]; if(ans<dp[i]) ans=dp[i]; } cout<<ans; return 0; }