Advertisement
999ms

Untitled

Oct 23rd, 2021
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct Candidate {
  6. string name;
  7. string surname;
  8. int day;
  9. int month;
  10. int year;
  11. int score;
  12. vector<string> universities;
  13. };
  14.  
  15. bool cmp_candidates(const Candidate &a, const Candidate &b) {
  16. return tie(b.score, a.year, a.month, a.day, a.surname, a.name) <
  17. tie(a.score, b.year, b.month, b.day, b.surname, b.name);
  18. }
  19.  
  20. bool cmp_students(const Candidate &a, const Candidate &b) {
  21. return tie(a.surname, a.name, a.year, a.month, a.day) <
  22. tie(b.surname, b.name, b.year, b.month, b.day);
  23. }
  24.  
  25. int main() {
  26. ios_base::sync_with_stdio(false);
  27. cin.tie(nullptr);
  28. cout.tie(nullptr);
  29.  
  30. int n;
  31. cin >> n;
  32. unordered_map<string, int> universities;
  33. while (n--) {
  34. string university;
  35. int count;
  36. cin >> university >> count;
  37. universities[university] = count;
  38. }
  39.  
  40. int m;
  41. cin >> m;
  42. vector<Candidate> candidates;
  43. candidates.reserve(m);
  44. while (m--) {
  45. Candidate candidate;
  46. int k;
  47. cin >> candidate.name >> candidate.surname >> candidate.day
  48. >> candidate.month >> candidate.year >> candidate.score
  49. >> k;
  50.  
  51. candidate.universities.reserve(k);
  52. while (k--) {
  53. string s;
  54. cin >> s;
  55. candidate.universities.push_back(s);
  56. }
  57. candidates.push_back(candidate);
  58. }
  59. stable_sort(candidates.begin(), candidates.end(), cmp_candidates);
  60.  
  61. map<string, vector<Candidate>> students;
  62.  
  63. for (const auto &candidate: candidates) {
  64. for (const auto &university: candidate.universities) {
  65. auto count = universities[university];
  66. if (count <= 0)
  67. continue;
  68. --count;
  69. universities[university] = count;
  70. students[university].push_back(candidate);
  71. break;
  72. }
  73. }
  74.  
  75. for (auto &[university, candidatesList]: students) {
  76. stable_sort(candidatesList.begin(), candidatesList.end(), cmp_students);
  77. cout << university;
  78. for (const auto &student: candidatesList) {
  79. cout << '\t' << student.name << ' ' << student.surname;
  80. }
  81. cout << '\n';
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement