Help me in solving DIET problem

My issue

the compiler is not showing the correct outputs… i’ve written the correct code which works on both the online compiler and visual studio

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	std::cin >> t;
	while(t--){
	    int n,k;
	    std::cin >> n >>k;
	    int sum=0;
	    int a[n];
	    int y=1;
	    
	    for (int i = 0; i < n; i++) {
	        /* code */
	        std::cin >> a[i];
	        sum+=a[i];
	        if(sum>=k){
	            sum=sum-k;
	            
	        }
	        else{
	            std::cout <<"NO "<< i+1 << std::endl;
	            y++;
	            break;
	        }
	  
	    }
	    
	    if(y==1){
	        std::cout << "yes" << std::endl;
	    }
	    
	    
	}
	return 0;
}

Problem Link: DIET Problem - CodeChef

@gfx_ironman
just a little logical mistake .
U have to take input of the while array first cozz .
U are breaking the loop in the middle of the taking inputs of array.
This can make other test cases taking wrong inputs.
i have correct your code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	std::cin >> t;
	while(t--){
	    int n,k;
	    std::cin >> n >>k;
	    int sum=0;
	    int a[n];
	    int y=1;
	    for(int i=0;i<n;i++)
	    {
	        std::cin>>a[i];
	    }
	    for (int i = 0; i < n; i++) {
	        /* code */
	       // std::cin >> a[i];
	        sum+=a[i];
	        if(sum>=k){
	            sum=sum-k;
	            
	        }
	        else{
	            std::cout <<"NO "<< i+1 << std::endl;
	            y++;
	            break;
	        }
	  
	    }
	    
	    if(y==1){
	        std::cout << "YES" << std::endl;
	    }
	    
	    
	}
	return 0;
}