Advertisement
alexgreb2001

Untitled

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