title: Minimum Cost Cut Board Squares
signature: function minimum_cost_cut_board_squares(x, y, m, n)
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;
  }
question_info.entry_fn_name: minimum_cost_cut_board_squares
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(x, y, m, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(x, y, m, n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({98, 97, 93, 90, 90, 87, 87, 87, 83, 77, 75, 73, 70, 70, 69, 67, 67, 61, 60, 59, 58, 58, 56, 53, 52, 46, 46, 44, 40, 37, 34, 33, 33, 33, 32, 28, 26, 25, 25, 23, 22, 22, 20, 18, 16, 9, 9, 1}, {99, 97, 96, 95, 92, 91, 88, 87, 86, 77, 74, 73, 73, 72, 71, 70, 70, 67, 63, 62, 60, 59, 56, 55, 55, 55, 50, 47, 45, 39, 39, 37, 35, 30, 30, 29, 27, 25, 23, 20, 19, 17, 16, 13, 10, 9, 3, 2}, 25, 27, 47899)
      print(string.format("TEST-0...%s",result))
  
      result = driver({78, 66, 66, 52, -4, -52, -72, -74}, {88, 84, 72, 30, -34, -40, -76, -78}, 6, 7, 76)
      print(string.format("TEST-1...%s",result))
  
      result = driver({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 15, 19, 119)
      print(string.format("TEST-2...%s",result))
  
      result = driver({97, 96, 89, 87, 83, 78, 77, 76, 67, 66, 63, 58, 54, 52, 48, 44, 38, 37, 28, 28, 19, 2}, {94, 92, 91, 83, 79, 75, 75, 72, 63, 63, 47, 40, 37, 36, 36, 33, 33, 29, 26, 19, 9, 5}, 13, 14, 13164)
      print(string.format("TEST-3...%s",result))
  
      result = driver({96, 90, 86, 78, 70, 32, 26, 26, 20, 16, 14, -2, -2, -4, -8, -10, -34, -44, -58, -60, -62, -62, -68, -72, -76, -78, -84}, {98, 92, 78, 66, 64, 50, 48, 42, 36, 26, 16, 16, 0, -4, -10, -18, -24, -32, -32, -48, -60, -62, -76, -82, -86, -98, -98}, 15, 24, -1650)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 25, 26, 341)
      print(string.format("TEST-5...%s",result))
  
      result = driver({75, 30}, {39, 10}, 1, 1, 153)
      print(string.format("TEST-6...%s",result))
  
      result = driver({96, 78, 74, 70, 70, 62, 60, 58, 50, 46, 44, 40, 38, 38, 36, 32, 24, 22, 16, 14, 10, 0, -8, -10, -10, -18, -20, -36, -52, -54, -56, -56, -60, -60, -68, -82, -96}, {94, 92, 92, 90, 86, 80, 78, 70, 64, 62, 46, 46, 40, 40, 32, 6, 4, -6, -14, -18, -20, -22, -24, -28, -34, -42, -50, -56, -62, -66, -76, -86, -86, -90, -92, -94, -96}, 19, 19, 14508)
      print(string.format("TEST-7...%s",result))
  
      result = driver({1, 0, 0, 0}, {1, 1, 1, 0}, 2, 2, 5)
      print(string.format("TEST-8...%s",result))
  
      result = driver({90, 81, 81, 74, 67, 40, 29, 25, 24, 13, 10}, {75, 74, 58, 53, 51, 49, 45, 25, 23, 14, 7}, 8, 10, 4117)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 47899, "inputs": {"x": [98, 97, 93, 90, 90, 87, 87, 87, 83, 77, 75, 73, 70, 70, 69, 67, 67, 61, 60, 59, 58, 58, 56, 53, 52, 46, 46, 44, 40, 37, 34, 33, 33, 33, 32, 28, 26, 25, 25, 23, 22, 22, 20, 18, 16, 9, 9, 1], "y": [99, 97, 96, 95, 92, 91, 88, 87, 86, 77, 74, 73, 73, 72, 71, 70, 70, 67, 63, 62, 60, 59, 56, 55, 55, 55, 50, 47, 45, 39, 39, 37, 35, 30, 30, 29, 27, 25, 23, 20, 19, 17, 16, 13, 10, 9, 3, 2], "m": 25, "n": 27}}, {"idx": 1, "outputs": 76, "inputs": {"x": [78, 66, 66, 52, -4, -52, -72, -74], "y": [88, 84, 72, 30, -34, -40, -76, -78], "m": 6, "n": 7}}, {"idx": 2, "outputs": 119, "inputs": {"x": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "y": [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "m": 15, "n": 19}}, {"idx": 3, "outputs": 13164, "inputs": {"x": [97, 96, 89, 87, 83, 78, 77, 76, 67, 66, 63, 58, 54, 52, 48, 44, 38, 37, 28, 28, 19, 2], "y": [94, 92, 91, 83, 79, 75, 75, 72, 63, 63, 47, 40, 37, 36, 36, 33, 33, 29, 26, 19, 9, 5], "m": 13, "n": 14}}, {"idx": 4, "outputs": -1650, "inputs": {"x": [96, 90, 86, 78, 70, 32, 26, 26, 20, 16, 14, -2, -2, -4, -8, -10, -34, -44, -58, -60, -62, -62, -68, -72, -76, -78, -84], "y": [98, 92, 78, 66, 64, 50, 48, 42, 36, 26, 16, 16, 0, -4, -10, -18, -24, -32, -32, -48, -60, -62, -76, -82, -86, -98, -98], "m": 15, "n": 24}}, {"idx": 5, "outputs": 341, "inputs": {"x": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "y": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "m": 25, "n": 26}}, {"idx": 6, "outputs": 153, "inputs": {"x": [75, 30], "y": [39, 10], "m": 1, "n": 1}}, {"idx": 7, "outputs": 14508, "inputs": {"x": [96, 78, 74, 70, 70, 62, 60, 58, 50, 46, 44, 40, 38, 38, 36, 32, 24, 22, 16, 14, 10, 0, -8, -10, -10, -18, -20, -36, -52, -54, -56, -56, -60, -60, -68, -82, -96], "y": [94, 92, 92, 90, 86, 80, 78, 70, 64, 62, 46, 46, 40, 40, 32, 6, 4, -6, -14, -18, -20, -22, -24, -28, -34, -42, -50, -56, -62, -66, -76, -86, -86, -90, -92, -94, -96], "m": 19, "n": 19}}, {"idx": 8, "outputs": 5, "inputs": {"x": [1, 0, 0, 0], "y": [1, 1, 1, 0], "m": 2, "n": 2}}, {"idx": 9, "outputs": 4117, "inputs": {"x": [90, 81, 81, 74, 67, 40, 29, 25, 24, 13, 10], "y": [75, 74, 58, 53, 51, 49, 45, 25, 23, 14, 7], "m": 8, "n": 10}}]