finish function greedy_k_portal