Why it is showing WA ?CATFEED

i am practising previous lunch time questions , i came across this problem from september lunch time :- https://www.codechef.com/LTIME76B/problems/CATFEED

it is easy problem ,here is my code ,it was showing SIGSEGV error ,error was fixed and now it is showing WA . i don’t know why it is showing WA.pls help

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()

{
    int t;
    cin>>t;
    
    while(t--)
    {
        int N,M;
        cin>>N>>M;
        
        int A[M],i,flag=0,j;
        for(i=0;i<M;++i)
        {
            cin>>A[i];
        }
        
        
        if(M>=N)
        {
        sort(A,A+N);                               //sorting first N values which we will use for comparing
        
        for(i=N;i<M;i+=N)
        {    
            flag=0;
             if((i+N)<M)                      //  check that i+N value is <=M-1
             {
                sort(A+i,A+(N+i));                    //sorting next N values
               
                for(j=i;j<N+i&&j<M;++j)
                { 
                    if(A[j]!=A[j-i])                     //comparing sorted values with previous sorted value
                    {
                        flag=1;
                        break;
                    }
                }
                
                if(flag==1)
                {
                    break;
                }
             }
             
             else
             {   
                 
                 if((M-1)-i==1)                                                       // for cases when i=8 and M=9  ,1 case 
                 {
                     if(A[i]==A[0])
                     {
                         flag=0;
                     }
                     else
                       {
                           flag=1;
                       }
                 }
                 else
                 {                                       //if more than 1 values are left as i+N is greater than M-1
                 sort(A+i,A+M);
                 for(j=i;j<M;++j)                             //sorting and comparing
                { 
                    if(A[j]!=A[j-i])
                    {
                        flag=1;
                        break;
                    }
                }
                
                if(flag==1)
                {
                    break;
                }
                 }
             }
        } 
        }
        
        
        else
        {
            sort(A,A+M);                    //if value of N >M
            
            for(i=0;i<M;++i)
            {
                for(j=i+1;j<M;++j)
                {
                    if(A[i]==A[j])
                    {  flag=1;
                        break;
                    }
                }
            }
        }
        
        if(flag==1)
        {
            cout<<"NO"<<endl;
        }
        else
        {
            cout<<"YES"<<endl;
        }
    }
}


Your array size is M and you are trying to sort N elements . Now consider the test case where value of M \lt N.
Try this test case:

1
100 2
1 2
3 Likes

oh i really missed that condition. thank you. is there any problem in the solution other than this. error is fixed but not it is showing WA , i don’t know what is going wrong