title: Minimum Cost Cut Board Squares
signature: func minimumCostCutBoardSquares(x []int, y []int, m int, n int) int {
source_py: def minimum_cost_cut_board_squares(X, Y, m, n):
      res = 0
      X.sort(reverse=True)
      Y.sort(reverse=True)
      hzntl = 1
      vert = 1
      i = 0
      j = 0
      while ((i < m) and (j < n)):
          if (X[i] > Y[j]):
              res += (X[i] * vert)
              hzntl += 1
              i += 1
          else:
              res += (Y[j] * hzntl)
              vert += 1
              j += 1
      total = 0
      while (i < m):
          total += X[i]
          i += 1
      res += (total * vert)
      total = 0
      while (j < n):
          total += Y[j]
          j += 1
      res += (total * hzntl)
      return res
source_cpp: int minimum_cost_cut_board_squares(vector<int> X, vector<int> Y, int m, int n) {
    int res = 0;
    sort(X.begin(), X.end(), greater < int > ( ) );
    sort(Y.begin(), Y.end(), greater < int > ( ) );
    int hzntl = 1, vert = 1;
    int i = 0, j = 0;
    while ( i < m && j < n ) {
      if ( X [ i ] > Y [ j ] ) {
        res += X [ i ] * vert;
        hzntl ++;
        i ++;
      }
      else {
        res += Y [ j ] * hzntl;
        vert ++;
        j ++;
      }
    }
    int total = 0;
    while ( i < m ) total += X [ i ++ ];
    res += total * vert;
    total = 0;
    while ( j < n ) total += Y [ j ++ ];
    res += total * hzntl;
    return res;
  }