Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct Candidate {
- string name;
- string surname;
- int day;
- int month;
- int year;
- int score;
- vector<string> universities;
- };
- bool cmp_candidates(const Candidate &a, const Candidate &b) {
- return tie(b.score, a.year, a.month, a.day, a.surname, a.name) <
- tie(a.score, b.year, b.month, b.day, b.surname, b.name);
- }
- bool cmp_students(const Candidate &a, const Candidate &b) {
- return tie(a.surname, a.name, a.year, a.month, a.day) <
- tie(b.surname, b.name, b.year, b.month, b.day);
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- cin >> n;
- unordered_map<string, int> universities;
- while (n--) {
- string university;
- int count;
- cin >> university >> count;
- universities[university] = count;
- }
- int m;
- cin >> m;
- vector<Candidate> candidates;
- candidates.reserve(m);
- while (m--) {
- Candidate candidate;
- int k;
- cin >> candidate.name >> candidate.surname >> candidate.day
- >> candidate.month >> candidate.year >> candidate.score
- >> k;
- candidate.universities.reserve(k);
- while (k--) {
- string s;
- cin >> s;
- candidate.universities.push_back(s);
- }
- candidates.push_back(candidate);
- }
- stable_sort(candidates.begin(), candidates.end(), cmp_candidates);
- map<string, vector<Candidate>> students;
- for (const auto &candidate: candidates) {
- for (const auto &university: candidate.universities) {
- auto count = universities[university];
- if (count <= 0)
- continue;
- --count;
- universities[university] = count;
- students[university].push_back(candidate);
- break;
- }
- }
- for (auto &[university, candidatesList]: students) {
- stable_sort(candidatesList.begin(), candidatesList.end(), cmp_students);
- cout << university;
- for (const auto &student: candidatesList) {
- cout << '\t' << student.name << ' ' << student.surname;
- }
- cout << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement