最大子段和

来源:互联网 发布:数据透视表行标签重复 编辑:程序博客网 时间:2024/06/05 06:53


AC代码:

#include<bits/stdc++.h>#define INF 0x3f3f3f3fusing namespace std;int main(){long long dp[50010];long long temp,maxn;long long N,i;while(cin>>N){temp=0,maxn=-INF;for(i=0;i<N;i++)    scanf("%lld",&dp[i]);    for(i=0;i<N;i++){    temp+=dp[i];    if(temp>maxn)maxn=temp;    if(temp<0)temp=0;    }    cout<<maxn<<endl;}return 0;}


0 0
原创粉丝点击