Minimum Task Cost

Company: Servicenow_8june

Difficulty: medium

Problem Statement

Minimum Task Cost Problem Description A group of n workers has gathered to complete a task. The worker at position i has an efficiency rating efficiency[i] . The workers are organised into pairs. The cost of a pair is the absolute difference of the two workers' efficiency ratings, and the cost of the task is the sum of the costs of all the pairs that are formed. Pairing everyone is impossible here, because n is odd. Exactly one worker is therefore left out, and the remaining n - 1 workers are split into (n - 1) / 2 pairs, with every remaining worker belonging to exactly one pair. Choose which worker to leave out, and how to pair up the rest, so that the cost of the task is as small as possible. Print that minimum cost. Input Format The first line contains a single integer n , the number of workers. Each of the next n lines contains a single integer, efficiency[i] , the efficiency rating of the worker at position i . Output Format Print a single integer on its own line: the minimum poss