Help me in solving DIET problem idk why my code complete with wrong answer

My issue

My code

#include <iostream>
#include<string>
#include <vector>
using namespace std;

int main() {

	int t;
	cin>>t;
	while(t--){
        
        int n, k;
        bool flag = false;
        int sum = 0;
        cin >> n >> k;
        vector<int> belok;
        for(int i = 0; i < n; i++){
            int a;
            cin >> a;
            belok.push_back(a);
        }
        for(int i = 0; i < n; i++){
            if(belok[i] >= k){
                belok[i] -= k;
                belok[i + 1] += belok[i];
            }
            else{
                cout << "NO " << i + 1 << endl;
                flag = true;
                
            }
        }
        if(flag == false){
            cout << "YES" << endl;
        }

    }
    
	return 0;
}

Problem Link: DIET Problem - CodeChef

@nemolucky
Just two little mistake first u have to break at first time when u get NO and second u can check for i+1 when i<n-1 .
I have corrected these in your code.
include
include
include
using namespace std;

int main() {

int t;
cin>>t;
while(t--){
    
    int n, k;
    bool flag = false;
    int sum = 0;
    cin >> n >> k;
    vector<int> belok;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        belok.push_back(a);
    }
    for(int i = 0; i < n; i++){
        if(belok[i] >= k){
            belok[i] -= k;
            if(i<n-1)
            belok[i + 1] += belok[i];
        }
        else{
            cout << "NO " << i + 1 << endl;
            flag = true;
            break;
            
        }
    }
    if(flag == false){
        cout << "YES" << endl;
    }

}

return 0;

}