make a for loop to iterate through the array.
in each iteration you calculate the x-difference and the y-difference.
if x and y-difference are both different from zero, then the distance does not go in only 1 direction, thus don't sum up that distance
if x or y difference is zero, add x and y to the sum of the distance (make sure you take the abs() value)
make a variable that holds the total distance so far (initialize it with zero)
Code
int totaldistancesofar = 0;
then in each step you do:
if (x == 0 || y== 0)
totaldistancesofar += abs(x+y);