Advertisement
STANAANDREY

ganju / serbare

Dec 11th, 2019
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. ifstream fin("serbare.in");
  5. ofstream fout("serbare.out");
  6.  
  7. typedef struct
  8. {
  9.     int nr = 0, id;
  10. } TIP;
  11.  
  12. TIP t[12];
  13. int n, p;
  14.  
  15. int main()
  16. {
  17.     fin >> n >> p;
  18.  
  19.     for (int i = 1; i <= p; i++)
  20.         t[i].id = i;
  21.  
  22.     for (int i = 0; i < n; i++)
  23.     {
  24.         int x, tip;
  25.         fin >> x >> tip;
  26.         t[tip].nr += x;
  27.     }
  28.  
  29.     int sortat = 0;
  30.     while (!sortat)
  31.     {
  32.         sortat = 1;
  33.         for (int i = 1; i < p; i++)
  34.             if (t[i].nr < t[i + 1].nr)
  35.             {
  36.                 swap(t[i], t[i + 1]);
  37.                 sortat = 0;
  38.             }
  39.     }
  40.  
  41.     for (int i = 1; i <= p; i++)
  42.         fout << t[i].id << ' ';
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement