Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <vector>
- #include <algorithm>
- int main() {
- std::map<std::string, int> min_subj;
- std::map<std::string, std::map<std::string, int>> stud_max;
- int N;
- std::cin >> N;
- for (int i = 0; i < N; i++) {
- std::string sname;
- int ps;
- std::cin >> sname >> ps;
- min_subj[sname] = ps;
- }
- int M;
- std::cin >> M;
- for (int i = 0; i < M; i++) {
- std::string name;
- std::string subj;
- if (!min_subj.count(subj)) {
- if (!stud_max.count(name))
- stud_max.insert(std::make_pair(name, std::map<std::string, int>()));
- continue;
- }
- int pts;
- std::cin >> name >> subj >> pts;
- (stud_max[name])[subj] = pts;
- }
- std::vector<std::pair<std::string, int>> mvec;
- for (auto& stud : stud_max) {
- auto& name = stud.first;
- auto& mmap = stud.second;
- int k = 0;
- for (auto& s : mmap)
- if (s.second >= min_subj[s.first])
- k++;
- mvec.push_back(std::make_pair(name, k));
- }
- std::sort(mvec.begin(), mvec.end(), [](const std::pair<std::string, int>& l, std::pair<std::string, int> r) {
- if (l.second != r.second)
- return l.second > r.second;
- else
- return l.first < r.first;
- });
- for(auto& r : mvec)
- std::cout << r.first << " " << r.second << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement