Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Tested by zydhanlinnar11 on May 28, 2022
- #include <iostream>
- #include <vector>
- #include <unordered_set>
- #include <set>
- #include <climits>
- #include <map>
- using namespace std;
- int main() {
- #ifdef ZYD_WSL
- freopen("/home/zydhanlinnar11/prakfinal-qa/in", "r", stdin);
- #endif
- int n, m, n_connection = 0;
- cin>>n;
- map<string, int> serverFloor;
- map<string, set<string>> storedIn;
- for(int i=0; i<n; i++) {
- string id; int n_data, floor;
- cin>>id>>n_data>>floor;
- serverFloor[id] = floor;
- for(int j=0; j<n_data; j++) {
- string data;
- cin>>data;
- storedIn[data].insert(id);
- }
- }
- cin>>m;
- for(int i=1; i<=m; i++) {
- set<string> connection;
- set<pair<int, string>> pq;
- int n_data, floor;
- cin>>n_data>>floor;
- for(int j=0; j<n_data; j++) {
- string data;
- cin>>data;
- if(storedIn[data].empty()) break;
- int diff = INT_MAX;
- for(auto &server: storedIn[data]) connection.insert(server), diff = min(diff, serverFloor[server]);
- pq.insert(make_pair(diff, data));
- }
- if (pq.empty()) cout<<"As Client "<<i<<" is unable to find the needed data, they went to the competitor instead :(\n";
- else cout<<"Client "<<i<<" got what they need\n";
- for(auto j=pq.begin(); j != pq.end(); j++) {
- cout<<(*j).second<<' ';
- auto server = storedIn[(*j).second].begin();
- cout<<*server; server++;
- for(; server != storedIn[(*j).second].end(); server++) cout<<"|"<<*server;
- cout<<"\n";
- }
- n_connection += connection.size();
- }
- cout<<"Number of connections: "<<n_connection<<'\n';
- }
Advertisement
RAW Paste Data
Copied
Advertisement