Given an array `nums` and an integer `k`, return the k most frequent elements. Break ties by smaller value, and return the result sorted ascending so it is deterministic.