Balife . diff += a[i] - load;

Logic behind this :- diff += a[i] - load;

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n, load = 0;
cin >> n;
ll int a[n];
for (int i = 0; i < n; i++)
{
cin >> a[i];
load += a[i];
}
if (load % n != 0)
{
cout << -1;
}
else
{
load = load / n;
ll diff = 0, max_load = 0;
for (int i = 0; i < n; i++)
{
diff += a[i] - load;
max_load = max(max_load, abs(diff));
}
cout << max_load;
}
return 0;
}