public static int getMax(int[] a) { int l = a.length; int start, all; start = all = a[l-1]; for(int n = l-2; n >= 0; n--) { start = Math.max(a[n], start + a[n]); all = Math.max(all, start); } return all; }