<awangdev>Max Sum of Rectangle No Larger Than K_1.java
public int maxSumSubmatrix(int[][] matrix, int k) {
        if (matrix == null || matrix.length == 0 || matrix[0] == null || matrix[0].length == 0) {
            return -1;
        }
        int m = Math.min(matrix.length, matrix[0].length);
        int n = Math.max(matrix.length, matrix[0].length);
        boolean rowFirst = matrix.length < matrix[0].length;
        int max = Integer.MIN_VALUE;
        for (int row = 0; row < m; row++) {
            int[] preSum = new int[n];
            for (int i = row; i < m; i++) { 
                TreeSet<Integer> areaSet = new TreeSet<>();
                int newSum = 0; 
                for (int j = 0; j < n; j++) {
                    preSum[j] += rowFirst? matrix[i][j] : matrix[j][i];
                    newSum += preSum[j];
                    if (newSum <= k) max = Math.max(max, newSum);
                    Integer extraArea = areaSet.ceiling(newSum - k);
                    if (extraArea != null) {
                        max = Math.max(max, newSum - extraArea);
                    }
                    areaSet.add(newSum);
                }
            }
        }
        return max == Integer.MIN_VALUE ? -1 : max;
    }
public int sample_funcname ( int [ ] [ ] var_0 , int var_1 ) {
  if ( var_0 == null || var_0 . length == 0 || var_0 [ 0 ] == null || var_0 [ 0 ] . length == 0 ) {
    return - 1 ;
  }
  int var_8 = Math . min ( var_0 . length , var_0 [ 0 ] . length ) ;
  int var_10 = Math . max ( var_0 . length , var_0 [ 0 ] . length ) ;
  boolean var_12 = var_0 . length < var_0 [ 0 ] . length ;
  int max = Integer . MIN_VALUE ;
  for ( int var_15 = 0 ;
  var_15 < var_8 ;
  var_15 ++ ) {
    int [ ] var_16 = new int [ var_10 ] ;
    for ( int var_17 = var_15 ;
    var_17 < var_8 ;
    var_17 ++ ) {
      TreeSet < Integer > var_19 = new TreeSet < > ( ) ;
      int var_20 = 0 ;
      for ( int var_21 = 0 ;
      var_21 < var_10 ;
      var_21 ++ ) {
        var_16 [ var_21 ] += var_12 ? var_0 [ var_17 ] [ var_21 ] : var_0 [ var_21 ] [ var_17 ] ;
        var_20 += var_16 [ var_21 ] ;
        if ( var_20 <= var_1 ) max = Math . max ( max , var_20 ) ;
        Integer var_23 = var_19 . ceiling ( var_20 - var_1 ) ;
        if ( var_23 != null ) {
          max = Math . max ( max , var_20 - var_23 ) ;
        }
        var_19 . add ( var_20 ) ;
      }
    }
  }
  return max == Integer . MIN_VALUE ? - 1 : max ;
}
