Help me in solving Chef Diet problem

My issue

include
using namespace std;
void diet(){
int N,K;
cin>>N>>K;
int P=0;
for(int i=1;i<=N;i++){
int A;
cin>>A;
P=P+A;
if(P>=K) P=P-K;
else{
cout<<“NO”<<" "<<i<<endl;
break;
}
if(i==N) cout<<“YES”<<endl;
}
}
int main() {
// your code goes here
int t;
cin>>t;
while(t–){
diet();
}
return 0;
}
i dont know why in the third test case its printing the wrong i value ,if we check it should print i as 3,can you check where it went wrong?

My code

#include <iostream>
using namespace std;
void diet(){
    int N,K;
    cin>>N>>K;
    int P=0;
    for(int i=1;i<=N;i++){
        int A;
        cin>>A;
        P=P+A;
        if(P>=K) P=P-K;
        else{
            cout<<"NO"<<" "<<i<<endl;
            break;
        }
     if(i==N) cout<<"YES"<<endl;
    }
}
int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    diet();
	}
	return 0;
}

Learning course: 1000 to 1400 difficulty problems
Problem Link: Chef Diet Practice Problem in - CodeChef

@csaicharanteja
refer the following 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;
}