https://www.codechef.com/problems/SALARY

Hello coders. I am a very beginner in competitive programming with very less knowledge of algorithm and data structures & problem solving skills. I was trying to solve the below question :
https://www.codechef.com/problems/SALARY

I was unable to come up with an efficient solution as my code was getting tle every time. So I just took a look on one of the successful submissions for this question. But I didn’t understand the approach.
Solution for the question is below :
#include<stdio.h>
int main()
{
int t, n, w[100], i, min, sum;
scanf("%d",&t);
while(t–)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&w[i]);
min=sum=w[0];
for(i=1;i<n;i++)
{
sum+=w[i];
if(min>w[i])
min=w[i];
}
printf("%d\n",(sum-(n*min)));
}
return 0;
}

I am unable to think how they came up with the formula " sum-(n*min) ". Can some body please help me with this?
Thank you in advance. Please help.

i think editorial of this solution is nicely explained.
Editorial: SALARY - Editorial