Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <vector>
- using namespace std;
- void find_top_town(map<string, unsigned long long> &town_cash, map<string, int> &town_days, int &day, int &prev_day) {
- string top_town;
- unsigned long long max_cash = 0;
- for (auto i:town_cash) {
- if (i.second > max_cash) {
- max_cash = i.second;
- top_town = i.first;
- }
- }
- int count = 0;
- for (auto i:town_cash) {
- if (i.second == max_cash) {
- count++;
- }
- }
- if (count == 1) {
- town_days.operator[](top_town) += (day - prev_day);
- }
- }
- int main() {
- map<string, unsigned long long> olig_cash;
- map<string, unsigned long long> town_cash;
- map<unsigned long long, vector<string> > cash_town;
- map<string, string> olig_town;
- map<string, int> town_days;
- unsigned long long cash;
- int n;
- cin >> n;
- string olig, town;
- for (int i = 0; i < n; i++) {
- cin >> olig >> town >> cash;
- olig_cash.operator[](olig) = cash;
- town_cash.operator[](town) += cash;
- olig_town.operator[](olig) = town;
- }
- for (auto i:town_cash) {
- cash_town[i.second].push_back(i.first);
- }
- for (auto i:cash_town) {
- cout << i.first << ' ' << i.second[0] << endl;
- }
- int days, moves;
- cin >> days >> moves;
- int day;
- string man, dest;
- int prev_day = 0;
- for (int i = 0; i < moves; i++) {
- cin >> day >> man >> dest;
- cout << i << endl;
- find_top_town(town_cash, town_days, day, prev_day);
- prev_day = day;
- string src_town = olig_town[man];
- if (town_cash.count(src_town) != 0) {
- if (cash_town[town_cash[src_town]].size() == 1) {
- cash_town.erase(town_cash[src_town]);
- } else {
- for (int i = 0; i < cash_town[town_cash[src_town]].size(); i++) {
- if (cash_town[town_cash[src_town]][i] == src_town) {
- cash_town[town_cash[src_town]].erase(cash_town[town_cash[src_town]].begin() + i);
- }
- }
- }
- }
- if (town_cash.count(dest) != 0) {
- if (cash_town[town_cash[dest]].size() == 1) {
- cash_town.erase(town_cash[dest]);
- } else {
- for (int i = 0; i < cash_town[town_cash[dest]].size(); i++) {
- if (cash_town[town_cash[dest]][i] == src_town) {
- cash_town[town_cash[dest]].erase(cash_town[town_cash[dest]].begin() + i);
- }
- }
- }
- }
- long long man_cash = olig_cash[man];
- town_cash.operator[](dest) += man_cash;
- town_cash.operator[](src_town) -= (man_cash);
- cash_town[town_cash[dest]].push_back(dest);
- cash_town[town_cash[src_town]].push_back(src_town);
- olig_town.operator[](man) = dest;
- }
- find_top_town(town_cash, town_days, days, prev_day);
- for (auto i:town_days) {
- cout << i.first << ' ' << i.second << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement