分析:
这是一道关于求最大子序列的问题。
可以通过遍历区间,并维护最大子集和·来求解。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define Ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fi first
#define se second
int t;
const int N = 300010;
ll x[200010],y[200010];
void solve()
{
int n,ans=0;
cin>>n;
int a[200010],b[200010];
for (int i=1;i<=n;i++){
cin>>a[i];
}
b[1]=a[1];
for (int i=2;i<=n;i++){
b[i]=max(b[i-1]+a[i],a[i]);
ans=max(ans,b[i]);
}
cout<<ans;
}
int main()
{
Ios
//in>>t;
t=1;
while(t--){
solve();
}
}
提示 :运用了前缀和了辅助。