Help me in solving DIET problem

My issue

My code

#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	for(int i=1;i<=t;i++){
	    int n,k;
	    cin>>n>>k;
	    int m;
	    for(int j=1;j<=n;j++){
	        cin>>m;
	    }
	   
	}
	return 0;
}

Problem Link: DIET Problem - CodeChef

Hey, this my code for the question

include
using namespace std;

int main()
{
int t,n,k,i;
cin>>t;

while(t--)
{
    int d=0,c=0;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<n;i++)
    {
        if(a[i]>=k)
        {
            d+=a[i]-k;
            c++;
        }
        
        else if(a[i]<k)
        {
            a[i]=a[i]+d;
            if(a[i]>=k)
            {
                d=a[i]-k;
                c++;
            }
            
            else if(a[i]<k)
            {cout<<"NO "<<i+1<<endl;
            
            break;}
        }
        
        
    }
    if(c==n)
    cout<<"YES"<<endl;
    
    
    
}


return 0;

}