alexgreb2001

Untitled

Oct 21st, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. ios::sync_with_stdio(false);
  10. cin.tie(NULL);
  11. cout.tie(NULL);
  12. map<string, unsigned long long> olig_cash;
  13. map<string, unsigned long long> town_cash;
  14. map<unsigned long long, vector<string> > cash_town;
  15. map<string, string> olig_town;
  16.  
  17. map<string, int> town_days2;
  18. unsigned long long cash;
  19. int n;
  20. cin >> n;
  21. string olig, town;
  22. for (int i = 0; i < n; i++) {
  23. ios::sync_with_stdio(false);
  24. cin >> olig >> town >> cash;
  25. olig_cash.operator[](olig) = cash;
  26. town_cash.operator[](town) += cash;
  27. olig_town.operator[](olig) = town;
  28. }
  29. for (auto i:town_cash) {
  30. cash_town[i.second].push_back(i.first);
  31. }
  32.  
  33.  
  34. int days, moves;
  35. cin >> days >> moves;
  36. int day;
  37. string man, dest;
  38. int prev_day = 0;
  39. for (int i = 0; i < moves; i++) {
  40. cin >> day >> man >> dest;
  41. map<unsigned long long, vector<string> >::iterator it;
  42. it = cash_town.end();
  43. it--;
  44. if (it->second.size() == 1) {
  45.  
  46. town_days2.operator[](it->second[0]) += (day - prev_day);
  47. }
  48.  
  49. prev_day = day;
  50. string src_town = olig_town[man];
  51.  
  52. if (town_cash.count(src_town) != 0) {
  53. if (cash_town[town_cash[src_town]].size() == 1) {
  54. cash_town.erase(town_cash[src_town]);
  55. } else {
  56. for (int i = 0; i < cash_town[town_cash[src_town]].size(); i++) {
  57. if (cash_town[town_cash[src_town]][i] == src_town) {
  58. cash_town[town_cash[src_town]].erase(cash_town[town_cash[src_town]].begin() + i);
  59. }
  60. }
  61. }
  62. }
  63.  
  64. if (town_cash.count(dest) != 0) {
  65. if (cash_town[town_cash[dest]].size() == 1) {
  66. cash_town.erase(town_cash[dest]);
  67. } else {
  68. for (int i = 0; i < cash_town[town_cash[dest]].size(); i++) {
  69. if (cash_town[town_cash[dest]][i] == src_town) {
  70. cash_town[town_cash[dest]].erase(cash_town[town_cash[dest]].begin() + i);
  71. }
  72. }
  73. }
  74. }
  75.  
  76.  
  77. long long man_cash = olig_cash[man];
  78. town_cash.operator[](dest) += man_cash;
  79. town_cash.operator[](src_town) -= (man_cash);
  80.  
  81. cash_town[town_cash[dest]].push_back(dest);
  82.  
  83. cash_town[town_cash[src_town]].push_back(src_town);
  84.  
  85. olig_town.operator[](man) = dest;
  86.  
  87.  
  88. }
  89.  
  90.  
  91. map<unsigned long long, vector<string> >::iterator it2;
  92. it2 = cash_town.end();
  93. it2--;
  94. if (it2->second.size() == 1) {
  95. town_days2.operator[](it2->second[0]) += (days - prev_day);
  96. }
  97. for (auto i:town_days2) {
  98. ios::sync_with_stdio(false);
  99. cout << i.first << ' ' << i.second << endl;
  100. }
  101. return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment