The total time can be calculated as:
• Reduce consequently, this number of customers who should wait is increasing, implying that the optimal course of action is for consumers to be served with greater service time.
Algorithm:

Explanation: Presume that there is indeed a better option than the greedy one.
• When sort data number of customers by time, the Greedy approach is employed. Customers are served once they have been sorted.
• A minimum of one pair of consecutive consumers is required for the best solution. Serving the second consumer takes less time than serving the first.
Take, for example, the requirement that "out of order" must be met by a pair of customers.
• Pair of customers denotes as and .
• Service time for the pair of customers denotes as and .
• By assumption, the service time of first customer is greater than the service time of second customer. That is,.
o Swap the order of the pair of customers will produce the better ordering. So, the second customer is served before the first customer .
• It does not change any waiting time of other customers.
o The waiting time for the customer will increase by and customer will increase by . So, the assumption of will reduces the overall waiting time.
• As a result, changing the order of the consumers results in the shortest overall waiting time.
Sorting the number of clients "n" will take a total of n minutes .
Each and every swap will reduce the total waiting time. So, after all the swaps are performed, the customers will be sorted in ascending order. The optimal solution becomes the greedy solution.
Therefore, the greedy solution must be the optimal solution.