问题描述:
Write a function to extract maximum and minimum k elements in the given tuple.

测试用例:
['assert extract_min_max((5, 20, 3, 7, 6, 8), 2) == (3, 5, 8, 20)', 'assert extract_min_max((4, 5, 6, 1, 2, 7), 3) == (1, 2, 4, 5, 6, 7)', 'assert extract_min_max((2, 3, 4, 8, 9, 11, 7), 4) == (2, 3, 4, 7, 8, 9, 11)']

生成的代码:
def extract_min_max(tup, k):
    sorted_tup = sorted(tup)
    min_elements = sorted_tup[:k]
    max_elements = sorted_tup[-k:]
    return tuple(min_elements + max_elements)

# Test cases
assert extract_min_max((5, 20, 3, 7, 6, 8), 2) == (3, 5, 8, 20)
assert extract_min_max((4, 5, 6, 1, 2, 7), 3) == (1, 2, 4, 5, 6, 7)
assert extract_min_max((2, 3, 4, 8, 9, 11, 7), 4) == (2, 3, 4, 7, 8, 9, 11)