Maximum subsequences and
# Include
# Include
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];/* accumulate to the right */if (first) // find the largest sum for the first time and {if (this_sum> = 0) {first = 0; old_first = old_last = I ;}} if (flag) // obtain 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;/* if a larger sum is found, the current result is updated */old_last = I; if (new_first! = Old_first) {old_first = new_first;} else if (this_sum <0)/* if the current subsequence is negative */{this_sum = 0; /* cannot increase the following and discard it */flag = 1;} printf ("% d \ n", max_sum, data [old_first], data [old_last]); return 0 ;}