Advertisement
35657

Untitled

Jun 7th, 2024
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6.  
  7. int main() {
  8.  
  9.     std::ifstream fin("input.txt");
  10.  
  11.     std::vector<std::pair<int, int>> vec(10001); // id, count
  12.  
  13.     int size, count, id;
  14.     fin >> size;
  15.  
  16.  
  17.     for (int i = 0; i < size; i++) {
  18.         fin >> id;
  19.         vec[id].first = id;
  20.         vec[id].second++;
  21.     }
  22.  
  23.     fin >> count;
  24.  
  25.     sort(vec.begin(), vec.end(), [](auto a, auto b) {
  26.         if (a.second == b.second) {
  27.             return a.first < b.first;
  28.         }
  29.         return a.second > b.second; });
  30.  
  31.     for (int i = 0; i < count; i++) {
  32.         if (vec[i].second != 0) {
  33.             std::cout << vec[i].first << " ";
  34.         }
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement