Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <vector>
- int main(int argc, const char * argv[]) {
- std::vector<int> v1 = {1, 3, 5, 7, 2, 4, 6, 8, 9, 11, 13, 10, 20, 8, 15, 14, 1, 2, 3, 4, 5, 6, 7, 8, 9};
- unsigned k = 3;
- auto it = std::next(v1.begin(), v1.size() - k);
- std::nth_element(v1.begin(), it, v1.end());
- std::copy(it, v1.end(), std::ostream_iterator<int>{std::cout, " "});
- std::cout << std::endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment