#include <bits/stdc++.h> #include<cstring> using namespace std; int main() { int n; while(scanf("%d",&n)!=EOF&&n!=0){ int a[n]; for(int i=0;i<n;i++) cin>>a[i]; int max=a[0]; for(int i=0;i<n;i++) {int x=0; for(int j=i;j<n;j++){ x=x+a[j]; if(max<x) max=x; } } cout<<max<<endl; } return 0; } |
Double click to view unformatted code.