public static int maxSubArray(int[] A) {
		int length = A.length;
		int sum = A[0];
		int auxSum, i;
		
		i = 0;
		
		while ((i < length) && (A[i] <= 0)) {
			if (sum < A[i]) {
				sum = A[i];
			}
			i++;
		}
		
		if (i == length) {
			return sum;
		}
		
		sum = auxSum = A[i++];
		while (i < length) {
			if (A[i] < 0) {
				if (auxSum > sum) {
					sum = auxSum;
				}
			}
			
			auxSum += A[i];
			
			if (auxSum < 0) {
				auxSum = 0;
			}
			
			i++;
		}
		
		if (sum < auxSum) {
			sum = auxSum;
		}
		
        return sum;
    }