#include <iostream> using namespace std; int main(){ int n; while(cin >> n){ if(!n) break; int input[n]; for(int i = 0; i < n; i++) cin >> input[i]; int left = 0, right = n-1, tmp, max = input[0], tmpMax; for(int i = 0; i < n; i++){ tmp = 0; tmpMax = input[i]; for(int j = i; j < n; j++){ tmp += input[j]; if(tmp > tmpMax) tmpMax = tmp; } if(tmpMax > max) max = tmpMax; } cout << max << endl; } return 0; } |
Double click to view unformatted code.