Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <unordered_map>
- #include <unordered_set>
- #include <vector>
- using namespace std;
- bool comp(const pair<string, int> &a, const pair<string, int> &b) {
- if (a.second != b.second) {
- return a.second > b.second;
- }
- return a.first < b.first;
- }
- int main() {
- int n, m, k;
- string a, b;
- unordered_map<string, int> minn;
- unordered_map<string, unordered_set<string> > pupil;
- cin >> n;
- for (int i = 0; i < n; ++i) {
- cin >> a >> k;
- minn[a] = k;
- }
- cin >> m;
- for (int i = 0; i < m; ++i) {
- cin >> a >> b >> k;
- pupil[a].insert("0");
- if (minn.find(b) != minn.end() && k >= minn[b]) {
- pupil[a].insert(b);
- }
- }
- vector<pair<string, int> > v;
- for (auto i = pupil.begin(); i != pupil.end(); ++i) {
- v.push_back({i->first, i->second.size() - 1});
- }
- sort(v.begin(), v.end(), comp);
- for (auto i = v.begin(); i != v.end(); ++i) {
- cout << i->first << ' ' << i->second << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement