Given the sequence of KK integers {n_1n 1, n_2n 2, ..., n_kn K}, continuous sub columns are defined as {n_in I, n_{i+1}n i+1, ..., N_jn J}, where 1 \le i \le j \ Le k1≤i≤j≤k. Maximum sub columns and is defined as the largest of all contiguous child column elements. For example, given the sequence {-2, 11,-4, 13,-5,-2}, its contiguous sub columns {11,-4, 13} have the largest and 20. You are asked to write a program that calculates the maximum number of columns for a given integer sequence.
This theme tests the performance of various algorithms in various data situations. The characteristics of each set of test data are as follows: Data 1: With the sample equivalent, test basic correctness; Data 2:102 random integers; Data 3:103 random integers; data 4:104 random integers; data 5:105 random integers; Input format:
Enter line 1th to give a positive integer KK (\le 100000≤100000), and the 2nd line gives a KK integer, which is separated by a space. Output format:
Outputs the largest columns in a row. If all integers in the sequence are negative, the output is 0. Input Sample:
6
-2 11-4 13-5-2
Output Sample:
20
Program code:
#include <iostream>
using namespace std;
int main ()
{
int N;
int num[100001]={0};
int max=0,sum=0;
cin>>n;
for (int i=0;i<n;i++)
cin>>num[i];
for (int i=0;i<n;i++)
{for
(int j=i;j<n;j++)
{
sum=sum+num[j];
if (Sum>max)
max=sum;
}
sum=0;
}
cout<<max;
} Stupid Way