SHARE
TWEET

Untitled

a guest Oct 18th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <string>
  5. #include <cmath>
  6. #include <map>
  7. #include <queue>
  8. #include <list>
  9. #include <set>
  10. #include <unordered_map>
  11.  
  12. //freopen("in.txt", "r", stdin);
  13. //freopen("out.txt", "w", stdout);
  14.  
  15. using namespace std;
  16. using ld = long double;
  17. using ll = long long;
  18. using ull = unsigned long long;
  19.  
  20. int main() {
  21.     ios::sync_with_stdio(0);
  22.     cin.tie(0);
  23.     cout.tie(0);
  24.  
  25.     unordered_map<string, ull> p, cn, ans;
  26.     unordered_map<string, string> pc;
  27.  
  28.     int n;
  29.     cin >> n;
  30.     for (int i = 0; i < n; i++) {
  31.         string s1, s2;
  32.         ull a;
  33.         cin >> s1 >> s2 >> a;
  34.         p[s1] = a;
  35.         cn[s2] += a;
  36.         pc[s1] = s2;
  37.     }
  38.  
  39. //    cout << p.size() << " " << cn.size() << " " << pc.size() << "\n";
  40. //
  41. //    for (auto [s, i] : cn) {
  42. //        cout << s << " " << i/1000000 << "\n";
  43. //    }
  44.  
  45.     set<pair<ull,string>> q;
  46.     for (pair<string, ull> p : cn) {
  47.         string s = p.first;
  48.         ull i = p.second;
  49.         q.insert({i, s});
  50.     }
  51. //    if ((*(q.end()--)).first != (*(q.end())).first) {
  52. //        ans[(*(q.end())).second]
  53. //    }
  54.  
  55.     int m, k;
  56.     cin >> m >> k;
  57.  
  58. //    cout << n << " " << m << " " << k << "\n";
  59. //    cout << q.size() << "\n";
  60.  
  61.     int last = 0;
  62.     for (int i = 0; i < k; i++) {
  63.         int a;
  64.         string s1, s2;
  65.         cin >> a >> s1 >> s2;
  66. //        cout << "\n";
  67. //        cout << a << "\n";
  68.         if ((q.size() == 1) || ((q.size() > 0) && ((*(--(--(q.end())))).first != (*(--(q.end()))).first))) {
  69.             ans[(*(--(q.end()))).second] += a - last;
  70. //            cout << "Hi " << (*(--(q.end()))).second << " " << a - last << "\n";
  71.         }
  72.         q.erase({cn[pc[s1]], pc[s1]});
  73.         q.erase({cn[s2], s2});
  74.         cn[pc[s1]] -= p[s1];
  75.         cn[s2] += p[s1];
  76.         q.insert({cn[pc[s1]], pc[s1]});
  77.         q.insert({cn[s2], s2});
  78.         pc[s1] = s2;
  79.         last = a;
  80. //        for (auto [s, i] : cn) {
  81. //            cout << s << " " << i/1000000 << "\n";
  82. //        }
  83. //        ans["kuku"] = 239;
  84.     }
  85. //    ans["ku"] = 239;
  86.  
  87.     if ((q.size() == 1) || ((q.size() > 0) && ((*(--(--(q.end())))).first != (*(--(q.end()))).first))) {
  88.         ans[(*(--(q.end()))).second] += m - last;
  89.     }
  90.  
  91.     vector<pair<string, int>> ansv;
  92.     for (pair<string, ull> p : ans) {
  93.         string s = p.first;
  94.         ull i = p.second;
  95.         ansv.push_back({s, i});
  96.     }
  97.  
  98.     sort(ansv.begin(), ansv.end());
  99.  
  100. //    cout << ans.size() << " " << ansv.size() << "\n";
  101. //    cout << "\n";
  102.  
  103.     for (pair<string, int> p : ansv) {
  104.         string s = p.first;
  105.         int i = p.second;
  106.         cout << s << " " << i << "\n";
  107.     }
  108.  
  109.     return 0;
  110. }
  111.  
  112. /*
  113. 5
  114. Abramovich London 15000000000
  115. Deripaska Moscow 10000000000
  116. Potanin Moscow 5000000000
  117. Berezovsky London 2500000000
  118. Khodorkovsky Chita 1000000000
  119.  */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top