my $heap = Heap->new; #### $heap->insert( $max); $heap->extract_min if $heap->size > $k; #### map $heap->extract_min, 1 .. $heap->size;