You are the manager of the hotel and you have N customers to serve. Each customer has a happiness quotient (Ci) if the food is served to him at time x. The unhappiness of a customer is defined by |Ci - x|. You must serve all the customers and you can serve them in any order. You have to find the minimum sum of unhappiness.
Note: At a particular time only one customer is served and Each customer takes one unit of time.
Contraint:
1 <= N <=10^3
1<= Ci <=N
Sample input:
4
2 2 3 3
Sample output:
2
Sample input:
4
1 1 1 1
Sample output:
6
Please give suggestions on how to solve this problem efficiently.