Alex_tz307

School - Level 2

Oct 30th, 2020 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("text.in");
  6. ofstream fout("text.out");
  7.  
  8. bool fcmp(const pair < int , int >& a, const pair < int , int >& b) {
  9.     return a.second > b.second || (a.second == b.second && a.first < b.first);
  10. }
  11.  
  12. int main() {
  13.     fin.sync_with_stdio(false);
  14.     fout.sync_with_stdio(false);
  15.     fin.tie(nullptr);
  16.     fout.tie(nullptr);
  17.     int N, P;
  18.     fin >> N >> P;
  19.     vector < int > freq(P);
  20.     for(int itr = 0; itr < N; ++itr) {
  21.         int id1, score1, id2, score2;
  22.         fin >> id1 >> score1 >> id2 >> score2;
  23.         if(score1 > score2)
  24.             ++freq[id1];
  25.         else
  26.             ++freq[id2];
  27.     }
  28.     vector < pair < int , int > > sol;
  29.     for(int i = 0; i < P; ++i)
  30.         sol.emplace_back(i, freq[i]);
  31.     sort(sol.begin(), sol.end(), fcmp);
  32.     for(auto x : sol)
  33.         fout << x.first << ' ' << x.second << '\n';
  34. }
  35.  
Add Comment
Please, Sign In to add comment