Help me in solving AVG problem

My issue

include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n,k,v;
cin>>n>>k>>v;
int arr[n];
int sum=0;

    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
   
   
   
    }
    int x=v*(n+k)-sum;
    
    
    if(x%k==0 && x>0)cout<<x/3<<endl;

    else cout<<-1<<endl;


}

}
I am not able to debug mistake.help…

My code


#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t; 
	cin>>t;
	while(t--)
	{
	    int n,k,v;
	    cin>>n>>k>>v;
	    int arr[n];
	    int sum=0;
	    
	    
	    for(int i=0;i<n;i++)
	    {
	        cin>>arr[i];
            sum+=arr[i];
	   
	   
	   
	    }
	    
        int x=v*(n+k)-sum;
	    
        
	    if( x%k==0 && x>0 )cout<<x/3<<endl;
	
	    else cout<<-1<<endl;
	

	}

}

Problem Link: Average Number Practice Coding Problem - CodeChef

@vishwajeet20ct
plzz refer my c++ solution for better understanding

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,k,v;
	    cin>>n>>k>>v;
	    int a[n];
	    int sm=0;
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	        sm+=a[i];
	    }
	    v=v*(n+k);
	    v-=sm;
	    if(v%k==0&&v>0)
	    cout<<v/k;
	    else
	    cout<<-1;
	    cout<<endl;
	}
	return 0;
}