Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- int main() {
- std::ifstream fin("input.txt");
- std::vector<std::pair<int, int>> vec(10001); // id, count
- int size, count, id;
- fin >> size;
- for (int i = 0; i < size; i++) {
- fin >> id;
- vec[id].first = id;
- vec[id].second++;
- }
- fin >> count;
- sort(vec.begin(), vec.end(), [](auto a, auto b) {
- if (a.second == b.second) {
- return a.first < b.first;
- }
- return a.second > b.second; });
- for (int i = 0; i < count; i++) {
- if (vec[i].second != 0) {
- std::cout << vec[i].first << " ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement