Advertisement
zydhanlinnar11

Bepi and His Library Servers

May 28th, 2022
645
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Tested by zydhanlinnar11 on May 28, 2022
  2. #include <iostream>
  3. #include <vector>
  4. #include <unordered_set>
  5. #include <set>
  6. #include <climits>
  7. #include <map>
  8. using namespace std;
  9.  
  10. int main() {
  11.     #ifdef ZYD_WSL
  12.         freopen("/home/zydhanlinnar11/prakfinal-qa/in", "r", stdin);
  13.     #endif
  14.     int n, m, n_connection = 0;
  15.     cin>>n;
  16.     map<string, int> serverFloor;
  17.     map<string, set<string>> storedIn;
  18.     for(int i=0; i<n; i++) {
  19.         string id; int n_data, floor;
  20.         cin>>id>>n_data>>floor;
  21.         serverFloor[id] = floor;
  22.         for(int j=0; j<n_data; j++) {
  23.             string data;
  24.             cin>>data;
  25.             storedIn[data].insert(id);
  26.         }
  27.     }
  28.     cin>>m;
  29.     for(int i=1; i<=m; i++) {
  30.         set<string> connection;
  31.         set<pair<int, string>> pq;
  32.         int n_data, floor;
  33.         cin>>n_data>>floor;
  34.         for(int j=0; j<n_data; j++) {
  35.             string data;
  36.             cin>>data;
  37.             if(storedIn[data].empty()) break;
  38.             int diff = INT_MAX;
  39.             for(auto &server: storedIn[data]) connection.insert(server), diff = min(diff, serverFloor[server]);
  40.             pq.insert(make_pair(diff, data));
  41.         }
  42.         if (pq.empty()) cout<<"As Client "<<i<<" is unable to find the needed data, they went to the competitor instead :(\n";
  43.         else cout<<"Client "<<i<<" got what they need\n";
  44.         for(auto j=pq.begin(); j != pq.end(); j++) {
  45.             cout<<(*j).second<<' ';
  46.             auto server = storedIn[(*j).second].begin();
  47.             cout<<*server; server++;
  48.             for(; server != storedIn[(*j).second].end(); server++) cout<<"|"<<*server;
  49.             cout<<"\n";
  50.         }
  51.         n_connection += connection.size();
  52.     }
  53.     cout<<"Number of connections: "<<n_connection<<'\n';
  54. }
Advertisement
RAW Paste Data Copied
Advertisement