Help me in solving TAKENOTLESS problem

My issue

include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t–){
long long n,i,c=0;
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
if(n==1)
cout<<“Marichka”<<endl;
else{
sort(a,a+n);
for(i=n-2;i>=0;i–){
if(a[i]==a[i+1])
++c;
else
break;
}
if(c%2==0||c==0)
cout<<“Marichka”<<endl;
else
cout<<“Zenyk”<<endl;
}
}
return 0;
}
What is the error in this code

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--){
	    long long n,i,c=0;
	    cin>>n;
	    int a[n];
	    for(i=0;i<n;i++)
	    cin>>a[i];
	    if(n==1)
	    cout<<"Marichka"<<endl;
	    else{
	        sort(a,a+n);
	        for(i=n-2;i>=0;i--){
	            if(a[i]==a[i+1])
	            ++c;
	            else
	            break;
	        }
	        if(c%2==0||c==0)
	        cout<<"Marichka"<<endl;
	        else
	        cout<<"Zenyk"<<endl;
	    }
	    }
	    return 0;
}

Problem Link: Take Not Less Practice Coding Problem

let the testcase be n=2
2 4 4
in this testcase the ans would be Marichka but you will be printing Zenyk
as marichhka can take out 2 stone from 1st pile array become
0 4 4
zenyk can take out 2,3,4 any no. of stone from a pile but marichka in next turn can take out all stones from another pile so Marichka wins as zenyk cannot make a move

1 Like