import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()) { int n=scanner.nextInt(); if(n==0) { break; } int[] ints=new int[n]; for(int i=0;i<n;i++) { ints[i]=scanner.nextInt(); } int ans=Integer.MIN_VALUE; for(int i=0;i<n;i++) { int temp=ints[i]; if(temp>ans) { ans=temp; } for(int j=i+1;j<n;j++) { temp+=ints[j]; if(temp>ans) { ans=temp; } } if(temp>ans) { ans=temp; } } System.out.println(ans); } } } |
Double click to view unformatted code.