Help me in solving NONNEGPROD problem

My issue

//Why this code is not applicable to NONNEGPROD problem.

include
using namespace std;

int main() {
int t;
cin >> t;
while(t–) {
int n;
cin >> n;
int a[n], m=1;
for(int i=0; i<n; i++) {
cin >> a[i];
m=m*a[i];
}
if(m<0) {
cout << 1 << endl;
}
else {
cout << 0 << endl;
}
}
return 0;
}

My code

#include <iostream>
using namespace std;

int main() {
	int t;
	cin >> t;
	while(t--) {
	    int n;
	    cin >> n;
	    int a[n], m=1;
	    for(int i=0; i<n; i++) {
	        cin >> a[i];
	        m=m*a[i];
	    }
	    if(m<0) {
	        cout << 1 << endl;
	    }
	    else {
	        cout << 0 << endl;
	    }
	}
	return 0;
}

Problem Link: NONNEGPROD Problem - CodeChef

The product ‘m’ can overflow easily hence will not store the correct result. Try thinking how can you be sure whether the product will be negative or positive without actually multiplying all the numbers.