While using std::sort to sort a range is reasonably fast, it is still wasteful if you only require the top few elements.
The std::partial_sort will only sort the top k elements with O(n*logk) time complexity and will even outperform std::nth_element if k is small compared to n.
Compiler Explorer link: https://compiler-explorer.com/z/Kjvj6bE9a