I Got AC. I just added 2 characters.

You are increasing votes for one index in advance. In line no. 17 you are incrementing `c[a[i]]`

but you should increment `c[a[i]-1]`

.

Here’s the AC solution link https://www.codechef.com/viewsolution/13199911

```
#include "bits/stdc++.h"
using namespace std;
int c[101];
int main() {
int t;
cin>>t;
while(t--)
{
memset(c,0,sizeof(c));
int n,k,ct=0;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
c[a[i]-1]++;
}
for(int i=0;i<n;i++)
{
if(c[i]>=k && a[i]!=i+1)
ct++;
}
cout<<ct<<endl;
}
}
```

EDIT:

In you code you are incrementing

```
c[a[i]]
```

but at the end you are comparing

```
if(c[i]>=k && a[i]!=i+1)
```

**The input data is 1 index based and you are incrementing one-based index but comparing that with zero based cause your loop is**

```
for(i=0;i<n;i++)
```

You can also get AC if you run your last loop **from i=1;i<=n;i++ and compare a[i] with i**

```
for(i=1;i<=n;i++)
{
if(c[i]>=k && a[i]!=i)
{
//code goes here
}
}
```

I hope this resolved your problem. Feel free to ask.