P1115 最大子段和

P1115 最大子段和

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5 + 10;

int n,a[maxn],dp[maxn];
int ans = -100010;

signed main(){
  // freopen("in","r",stdin);
    ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++){
        dp[i] = max(a[i],dp[i - 1] + a[i]);
        ans = max(ans,dp[i]);
    }

    cout <<  ans << endl;
    return 0;
}
View Code

 

posted @ 2025-09-17 08:38  Hazelxcf  阅读(4)  评论(0)    收藏  举报