P1115 最大子段和
点击查看代码
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
cin>>n;
int x;
int ans=-2e9;
int dp=-2e9;
for(int i=1;i<=n;i++){
cin>>x;
dp=max(dp+x,x);
ans=max(dp,ans);
}
cout<<ans<<"\n";
return 0;
}

浙公网安备 33010602011771号