Unable to find logical error - STUDVOTE

PROBLEM - STUDVOTE

After trying for quite a while and comparing my code with submissions, I’m unable to find the error in my code. Any hint or assistance is appreciated :slight_smile:

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int n,k;
	    int ctr=0;
	    int input;
	    cin>>n>>k;
	    map <int,int> freq;
	    
	    int arr[n];
	    
	    for(int i=0;i<n;++i){
	        cin>>input;
	        arr[i]=input;   
	        if(input==(i+1)){  //checking whether the person has voted for themselves
	            arr[i]=0;
	        }
	    }
	    
	   for(auto d: arr){
	            freq[d]+=1;  //frequency map
	    }
	    
	    for(auto d: freq){
	       
	        if((d.second>=k)&&(d.first!=0)){  //comparing the frequency and those that exceed the required criteria can get in
	            ctr++;
	        }
	    }
	    
	    cout<<ctr<<endl;
	    
	    
	}
	return 0;
}