LPOJ - 5546 最大子段和

Description

给出一段序列,选出其中连续且非空的一段使得这段和最大。

Input

第一行是一个正整数NN,表示了序列的长度。

第二行包含NN个绝对值不大于1000010000的整数AiAi,描述了这段序列。

Output

一个整数,为最大的子段和是多少。子段的最小长度为11。

Sample Input 1Copy

7 2 -4 3 -1 2 -4 3

Sample Output 1

4

Source

LPOJ

Hint

【样例说明】

2,−4,3,−1,2,−4,32,−4,3,−1,2,−4,3中,最大的子段和为4,该子段为3,−1,23,−1,2.

【数据规模与约定】

对于40%40%的数据,有N≤2000N≤2000。

对于100%100%的数据,有N≤200000N≤200000。

#include 
using namespace std;
long long n,s[200000],i,j,max,x[200000],m;
int main()
{
	
	scanf("%lld",&n);
	m=n;
	for (i=0;i0) x[i]=x[i-1]+s[i];
		else {
			x[0]=s[0];
			max=s[0];
		}
		if (max

你可能感兴趣的:(蓝桥杯,c语言,职场和发展)