SHARE
TWEET

Untitled

a guest Oct 18th, 2019 67 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 (auto [s, i] : cn) {
  47.         q.insert({i, s});
  48.     }
  49. //    if ((*(q.end()--)).first != (*(q.end())).first) {
  50. //        ans[(*(q.end())).second]
  51. //    }
  52.  
  53.     int m, k;
  54.     cin >> m >> k;
  55.  
  56. //    cout << n << " " << m << " " << k << "\n";
  57. //    cout << q.size() << "\n";
  58.  
  59.     int last = 0;
  60.     for (int i = 0; i < k; i++) {
  61.         int a;
  62.         string s1, s2;
  63.         cin >> a >> s1 >> s2;
  64. //        cout << "\n";
  65. //        cout << a << "\n";
  66.         if ((q.size() == 1) || ((q.size() > 0) && ((*(--(--(q.end())))).first != (*(--(q.end()))).first))) {
  67.             ans[(*(--(q.end()))).second] += a - last;
  68. //            cout << "Hi " << (*(--(q.end()))).second << " " << a - last << "\n";
  69.         }
  70.         q.erase({cn[pc[s1]], pc[s1]});
  71.         q.erase({cn[s2], s2});
  72.         cn[pc[s1]] -= p[s1];
  73.         cn[s2] += p[s1];
  74.         q.insert({cn[pc[s1]], pc[s1]});
  75.         q.insert({cn[s2], s2});
  76.         pc[s1] = s2;
  77.         last = a;
  78. //        for (auto [s, i] : cn) {
  79. //            cout << s << " " << i/1000000 << "\n";
  80. //        }
  81. //        ans["kuku"] = 239;
  82.     }
  83. //    ans["ku"] = 239;
  84.  
  85.     if ((q.size() == 1) || ((q.size() > 0) && ((*(--(--(q.end())))).first != (*(--(q.end()))).first))) {
  86.         ans[(*(--(q.end()))).second] += m - last;
  87.     }
  88.  
  89.     vector<pair<string, int>> ansv;
  90.     for (auto [s, i] : ans) {
  91.         ansv.push_back({s, i});
  92.     }
  93.  
  94.     sort(ansv.begin(), ansv.end());
  95.  
  96. //    cout << ans.size() << " " << ansv.size() << "\n";
  97. //    cout << "\n";
  98.  
  99.     for (auto [s, i] : ansv) {
  100.         cout << s << " " << i << "\n";
  101.     }
  102.  
  103.     return 0;
  104. }
  105.  
  106. /*
  107. 5
  108. Abramovich London 15000000000
  109. Deripaska Moscow 10000000000
  110. Potanin Moscow 5000000000
  111. Berezovsky London 2500000000
  112. Khodorkovsky Chita 1000000000
  113.  */
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