```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 ``` ```#include #include #include using namespace std; int find_max(int *arr, int arrlen, int *start, int *count) { struct node { int from, to, sum; }; node seh = {0, -1, 0}; node best = seh; for(seh.to = 0; seh.to < arrlen; ++seh.to) { const int newSum = seh.sum + arr[seh.to]; if(newSum > arr[seh.to]) { seh.sum = newSum; } else { seh.from = seh.to; seh.sum = arr[seh.to]; } if(best.sum < seh.sum) best = seh; } *start = best.from; *count = best.to - best.from + 1; return best.sum; } int main(int c, char *const *v) { int count = c-1; vector vi(count); if(count < 1) { cout << "Error: No command line arguments found" << endl; cout << "Testing dummy data set: {4, -3, -2, 2, 3, -1, 3, -12, 5, -9, 0, -1}" << endl; int a[] = {4, -3, -2, 2, 3, -1, 3, -12, 5, -9, 0, -1}; count = static_cast( sizeof a / sizeof a[0] ); vi.insert(vi.begin(), a, a + count); } else { for(int i = 1; i < c; ++i) stringstream(v[i]) >> vi[i-1]; } int *arr = &vi[0]; int st, cn; const int s = find_max(arr, count, &st, &cn); cout << s << ':'; for(int i= 0; i < cn; ++i) cout << arr[st+i] << ' '; cout << endl; return 0; } ```
 ```1 2 3 ``` ```Error: No command line arguments found Testing dummy data set: {4, -3, -2, 2, 3, -1, 3, -12, 5, -9, 0, -1} 7:2 3 -1 3 ```