What's wrong in my solution

c-plus-plus
easy
problem
wa

#1

problem link:-https://www.codechef.com/problems/SALARY
My solution:-https://www.codechef.com/viewsolution/18786597


#2

you are taking the min wrong first you are making mn=ar[0] then checking
consider the array 3 2 5 6 your code will return min as 3 but actual min is 2 and also the way you are calculating the ans is wrong as max can change when you increment the other salaries as salaries can be equal so you need to sort the array and add max-min (max=ar[n-1],min=ar[0]) to all the elements from 0 to n-2 as ar[n-1] would be the max add max-min to ans while max!= min then print ans