洛谷P3009
作者:互联网
title: "最大连续子段和"
author: Sun-Wind
date: February 20,2022
#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
#define fi(i,a,b) for(int i = a; i <= b; ++i)
#define fr(i,a,b) for(int i = a; i >= b; --i)
#define x first
#define y second
#define sz(x) ((int)(x).size())
#define pb push_back
using pii = pair<int,int>;
//#define DEBUG
const int N = 1e5 + 5;
int cow[N];
int f[N];//从第n个数开头得最大子段和
int maxx = -0x3f3f3f3f;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
fi(i,1,n) cin >> cow[i];
f[n] = cow[n];
fr(i,n-1,1) {
f[i] = max(cow[i],f[i+1] + cow[i]);
}
fi(i,1,n){
maxx = max(maxx,f[i]);
}
cout << maxx << endl;
#ifdef DEBUG
//freopen(D:\in.txt,r,stdin);
#endif
return 0;
}
标签:maxx,洛谷,cow,int,cin,P3009,fi,define 来源: https://www.cnblogs.com/Sun-Wind/p/15914999.html