Help me in solving GFTSHP problem ...what wrong in my code?

My issue

My code

#include <iostream>
#include<algorithm>
using namespace std;

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

Problem Link: CodeChef: Practical coding for everyone

@deepakjdh31
Just implementation mistakes
i have corrected your code hope u will get it.

#include <iostream>
#include<algorithm>
using namespace std;

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