#include <stdio.h> #include <stdlib.h>int main () {int this_sum, max_sum, Old_first, Old_last, New_first;int N , I, TMP, flag = 1;int first = 1;int *data;scanf ("%d", &n); this_sum= max_sum = Old_first = New_first = 0;old_last = N- 1;data = (int *) malloc (n * sizeof (int)); for (i = 0; i < n; i + +) { scanf ("%d", &data[i]); } for (i = 0; i < n; i++) {this_sum + = data[i];/* to the right to accumulate */if (first)//to find the largest and {if (this_sum >= 0) {= 0;old_first = Old_ last = i;}} if (flag)//Gets the beginning of the new This_sum {if (this_sum >= 0) {flag = 0;new_first = i;}} if (This_sum > max_sum) {max_sum = this_sum;/* found larger and, then update current results */old_last = i;if (New_first! = Old_first) {Old_first = New_f Irst;}} else if (This_sum < 0)/* If the current sub-sequence and is negative */{this_sum = 0;/* It is not possible to make the back and increase, discard the */flag = 1;}} printf ("%d%d%d\n", Max_sum, Data[old_first], data[old_last]); return 0;}
Maximum sub-sequences and