Help me in solving STUDVOTE problem

My issue

Says WA but I can’t figure it why or where my code is wrong… can’t think of any test cases where it gives WA for me. Basically if a student voted for himself I am setting all his votes to 0 and then counting number of qualified candidates (minus 1 in case of large number of 0 votes)

My code

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

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  

    int t,n,k;
    cin >> t;
    while (t--)
    {
        cin>>n>>k;
        int  a[n], dis[n]={0};
        for (int i=0; i<n;i++){
            cin>>a[i];
            if(a[i]==i+1) 
                dis[i]++;
        }

        for (int i=0; i<n;i++){ 
            if(dis[a[i]-1])
                a[i]=0;
        }

        int cur_cnt=1, tot_cnt=0;
        sort(a, a+n);
        for (int i=1; i<n;i++){
            if(a[i]==a[i-1]){
                cur_cnt++;
                if(i==n-1 && cur_cnt>=k)
                    tot_cnt++;
            }
            else {
                if(cur_cnt>=k)
                    tot_cnt++;
                cur_cnt=1;
            }
        }
        tot_cnt -= (count(a,a+n,0)>=k)?1:0;
        cout<<tot_cnt<<endl; 
    }   

    return 0;
}

Problem Link: STUDVOTE Problem - CodeChef

@aditya_raj0303
your code is failing for
1
1 1
1
its printing -1