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[] a = new int[n]; for(int i = 0;i < n;i++) { a[i] = scanner.nextInt(); } int t = 0; int max = a[0]; for(int i = 0;i < n;i++) { t += a[i]; if(max < t) { max = t; } if(t < 0) { t = 0; } } System.out.println(max); } } } |
Double click to view unformatted code.