fork(1) download
  1. #include <iostream>
  2. #include<map>
  3. #include<set>
  4. using namespace std;
  5.  
  6. typedef int ll;
  7. map<ll,ll>count;
  8. map<ll,ll>maxcount;
  9. set<int>s;
  10. set<ll> :: iterator it;
  11.  
  12. int main() {
  13. // your code goes here
  14. ll test;
  15. cin>>test;
  16. while(test--)
  17. {
  18. ll n,i,ma=0,mi=10000;
  19. cin>>n;
  20. ll a[n+1];
  21. count.clear();
  22. maxcount.clear();
  23. s.clear();
  24. for(i=0;i<n;i++)
  25. {
  26. cin>>a[i];
  27. count[a[i]]++;
  28. if(ma<a[i])
  29. ma=a[i];
  30. if(a[i]<mi)
  31. mi=a[i];
  32. }
  33. // cout<<mi<<" "<<ma<<endl;
  34.  
  35. for(i=mi;i<=ma;i++)
  36. {
  37. if(count[i]!=0)
  38. {
  39. //cout<<count[i]<<" ";
  40. s.insert(count[i]);
  41. if(maxcount[count[i]]==0)
  42. maxcount[count[i]]=i;
  43. else if(maxcount[count[i]]>i)
  44. maxcount[count[i]]=i;
  45. }
  46. }
  47.  
  48. int last;
  49.  
  50. for(it=s.begin(); it!=s.end(); ++it)
  51. {
  52. last=*it;
  53. // cout<<*it<<" ";
  54. }
  55. cout<<maxcount[last]<<" "<<last<<endl;
  56. }
  57. return 0;
  58. }
Success #stdin #stdout 0s 3436KB
stdin
3
4
123 14 124 56
3
1 2 1
6
1 2 3 4 5 6
stdout
14 1
1 2
1 1