#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
map<string,vector<string>> country_name;
map<string,int> name_votes;
string name,country,wname,wcountry;
for(int i=0;i<n;i++){
cin>>name>>country;
country_name[country].push_back(name);
}
for(int i=0;i<m;i++){
cin>>name;
if(name_votes.find(name)==name_votes.end())
name_votes.insert({name,1});
else
name_votes[name]+=1;
}
long maxi0=0,maxi=0;
map<string,vector<string>>:: iterator it;
for(it=country_name.begin();it!=country_name.end();it++){
if(it->second.size()>maxi0){
maxi0=(it->second).size();
wcountry=it->first;
}
if(it->second.size()==maxi0){
if(it->first<wcountry)
wcountry=it->first;
}
}
map<string,int>:: iterator it2;
for(it2=name_votes.begin();it2!=name_votes.end();it2++){
if((it2->second)>maxi){
maxi=it2->second;
wname=it2->first;
}
if(it2->second==maxi){
if(it2->first<wname)
wname=it2->first;
}
}
cout<<wcountry<<endl;
cout<<wname<<endl;
return 0;
}
What is the issue?
1 Like
its giving correct ans on the given test cases, but gives Wrong Answer on submitting.
I have used only two maps one for country-name and other for name-votes
Your wcountry
is defined as the country with the longest vector size, i.e the one having highest number of chefs, whereas it should’ve been the the country having the highest number of votes for its chefs. This is one of the bugs I could spot easily, there might be more.
2 Likes
Thanks that was a blunder i was making (didn’t read the ques correctly). It got accepted now.