import heapq


def k_closest_heapq_nsmallest(points: list[list[int]], K: int) -> list[list[int]]:
    """K-closest via `heapq.nsmallest(n, items)`

    Complexity:
        K = len(heap)
            Time: O(NlogK) N heap push/pop operations on heap with size ≤ K
            Space: O(K) priority queue of size K

    Args:
        points:
        K:

    Returns: K-closest points to the origin

    Examples:
        >>> k_closest_heapq_nsmallest([[1,3],[-2,2]], 1)
        [[-2, 2]]
        >>> k_closest_heapq_nsmallest([[3,3],[5,-1],[-2,4]], 2)
        [[3, 3], [-2, 4]]

    """
    compute_distance = lambda point: sum(coord ** 2 for coord in point)
    return heapq.nsmallest(K, points, key=compute_distance)