# Getting WA for CATFEED

Getting WA for my code, help me out where have i gone wrong?
https://www.codechef.com/LTIME76B/problems/CATFEED

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

int main()
{
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif

``````int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;

int ar[m+1];
for(int i=1; i<=m; i++)
cin >> ar[i];

bool flag = true;
// Divivde these operation in terms of 'N'
int i, k;
for(i=1, k=1; i<=m; i++){
if(i%n == 0){
// sort every n size block and
// check if all the elemement are distinct
sort(ar+k, ar+i+1);

for(int l=k; l<=i-1; l++){
if(ar[l]!=ar[l+1]){
flag = true;
}
else{
flag = false;
break;
}
}
k = i+1;
}
}

// cout <<" K : " << k << endl;
// Left over check
if(k<m && flag!=false){
sort(ar+k, ar+m+1);
for(int x=k; x<=m; x++){
//cout << ar[x] << " ";
if(ar[x]!=ar[x+1]){
flag = true;
}
else{
flag = false;
break;
}
}
//cout << endl;
}

cout << (flag ? "YES\n" : "NO\n");
}
return 0;
``````

}