Help me in solving BUDGET25 problem

My issue

help me some of the test cases getting failed…

My code

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

int main() {
	// your code goes here
int t;
cin>>t;
while(t--)
{
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    int sum=0,count=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>=k)
        {
            sum+=(a[i]-k);
            count++;
        }   
    }
    if(k==1)
    {
        cout<<n<<endl;
    }
    else
    {
    sort(a.begin(),a.end());
    //for(int i=0;i<n;i++)
    //cout<<a[i]<<endl;
    int i=0;
    while(sum>0)
    {
        if(a[i]<=sum)
        {
            sum-=a[i];
            i++;
            count++;
        }
        else
        break;
    }
    cout<<count<<endl;
    }
}
}

Problem Link: Budget Allotment Practice Coding Problem