Help me in solving SANTACHOC problem

My issue

can anyone help me know what is wrong in this code ?

include
using namespace std;

int main() {
int t ;
cin >> t;
while (t–){
int n, k, sum = 0;
cin >> n >> k;
int i = 0;
int a[n];
while (n–){
cin >> a[i];
sum += a[i];
i ++;
}
if (sum < n ) cout << “nO” << endl;
else if (sum % n != 0 || k == 0){
cout << “NO” << endl;
}
else {
cout << “YES” << endl;
}
}
return 0;
}

My code

#include <iostream>
using namespace std;

int main() {
	int t ;
	cin >> t;
	while (t--){
	    int n, k, sum = 0;
	    cin >> n >> k;
	    int i = 0;
	    int a[n];
	    while (n--){
	        cin >> a[i];
	        sum += a[i];
	        i ++;
	    }
	    if (sum < n ) cout << "nO" << endl;
	    else if (sum % n != 0 && k == 0){
	        cout << "NO" << endl;
	    } 
	    else {
	        cout << "YES" << endl;
	    }
	}
	return 0;
}

Problem Link: SANTACHOC Problem - CodeChef

@aishchi
by doing n–(inside while loop) , u are changing the value of n and making it as 0.
and u can’t compare sum <n because n value has been changed.

Got it !
Thank you .