Help me in solving AVG problem

My issue

if i write the code like this i fail in test case
if(x<0 || x%k != 0) cout << -1<< endl;
else cout << x/k<<endl;
if i write it like this, test case gets passed why so?
if(x>0 && x%k == 0) cout << x/k<< endl;
else cout << -1<<endl;

My code

#include <iostream>
using namespace std;

int main() {
	int t;
	cin >> t;
	while(t--){
	    int n,k,v;
	    cin>> n>>k>>v;
	    int arr[n];
	    int sum_n = 0;
	    for(int i = 0;i<n;i++){
	        cin >> arr[i];
	        sum_n += arr[i];
	    }
	    int a = v*(n+k);
	    int x = a - sum_n;
	    if(x<0 || x%k != 0) cout << -1<< endl;
	    else cout << x/k<<endl;
	}
	return 0;
}

Problem Link: Average Number Practice Coding Problem - CodeChef

@draj_skr
the answer will differ for x==0

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

int main() {
    int t;
    cin >> t;

    while (t--) {
        int n, k, v;
        cin >> n >> k >> v;

        // Use vector for dynamic array
        vector<int> arr(n);
        int sum_n = 0;

        for (int i = 0; i < n; i++) {
            cin >> arr[i];
            sum_n += arr[i];
        }

        int a = v * (n + k);
        int x = a - sum_n;

        // Check for division by zero and validate input
        if (k == 0 || x < 0 || x % k != 0)
            cout << -1 << endl;
        else
            cout << x / k << endl;
    }

    return 0;
}

here it is the correct form of it