fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define nl "\n"
  5. #define see(x) cout<<#x<<" is :"<<x<<nl;
  6. #define test() long long t; cin>>t; while(t--)
  7.  
  8.  
  9. int main(){
  10. //ios_base::sync_with_stdio(false); cin.tie(NULL);
  11. int n, m, mv=0, mc=0;
  12. cin>>n>>m;
  13. map<string , int> vote, country;
  14. string chef, ctry;
  15.  
  16. for(int i=0; i<n; i++){
  17. cin>>chef>>ctry;
  18. vote[chef] = 0;
  19. country[ctry]++;
  20. if(mc<country[ctry])
  21. mc = country[ctry];
  22. }
  23.  
  24. for(int i=0; i<m; i++){
  25. string s;
  26. cin>>s;
  27. vote[s]++;
  28. if(mv<vote[s])
  29. mv = vote[s];
  30. }
  31.  
  32. for(auto it : vote){
  33. if(it.second == mv){
  34. chef = it.first;
  35. break;
  36. }
  37. }
  38. for(auto it : country){
  39. if(it.second == mc){
  40. ctry = it.first;
  41. break;
  42. }
  43. }
  44.  
  45. cout<<ctry<<nl<<chef;
  46. return 0;
  47. }
Success #stdin #stdout 4.79s 4708KB
stdin
Standard input is empty
stdout