Stuck at a simple problem

Can someone explain why my solution is wrong ?

problem : CodeChef: Practical coding for everyone
solution : CodeChef: Practical coding for everyone

your code failed in this case:

1
3
1 2 2

should be Marichka. Marichka take 1, no matter what Zenyk take, Marichka will win

1 Like

#include
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t–)
{
int n;
cin>>n;
int a[n];
map<int,int>mp;
for(int i=0;i<n;i++)cin>>a[i];
sort(a,a+n);
int flag=1;
for(int i=n-1;i>=0;i–)mp[a[i]]++;
if(mp[a[n-1]]%2==0)cout<<“Zenyk\n”;
else cout<<“Marichka\n”;

}
return 0;

}
why this not running and why editorial is checking for all elements if if can see only the count of largest element if odd then marchika and if even then zenyk…

send link to your solution

thanks @henrychen . My logic was wrong.