Balife question test cases

test case 0 not passed for the code .
#include
using namespace std;

int main() {
// your code goes here
int mx=0,l=0,dif=0,n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
l+=a[i];
}
if(l%n!=0)
{
cout<<"-1"<<endl;
}
l=l/n;
for(int i=0;i<n;i++)
{
dif+=a[i]-l;
int ans=max(dif,-dif);
mx=max(mx,ans);
}
cout<<mx<<endl;
return 0;
}

@mishranavneet1710
Your code gave wrong ans for this test case
Q : 2
49 50
A : -1

Please close the doubt