Describe
given an integer sequence {A1,a2...,an}, find the continuous non-empty string {ax,ax+1,..., ay}, making the subsequence and the largest, wherein, 1<=x<=y<=n.
-
-
Input
-
The
-
first line is an integer N (n<=10) that represents the number of groups of test data)
The first line of each set of test data is an integer n indicating that the sequence has n integers, followed by n integers I ( -100=<i<=100), representing all the elements in the series. (0<n<=1000000)
Output
for each set of test data output and the maximum contiguous substring of the and.
Sample input
151 2-1 3-2
Sample output
5
Tips
a lot of input data, it is recommended to use scanf for input
Source
Classic Questions
Uploaded by
Zhang Yunzun
#include <iostream> #include <stdio.h>using namespace Std;int main () {int T,n,a,i;int max,sum;while (cin> >t) {while (t--) {cin>>n;cin>>a;max=sum=a;for (i=1;i<n;i++) {if (Sum>max) max=sum;if (sum<0) Sum=0;cin>>a;sum+=a;} Cout<<max<<endl;}} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Sub-string and