Queuing for Water


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
Python

There are n people lining up to fetch water from 1 tap. The time required for the i-th person to fill their bucket is ti. How should their order of fetching water be arranged to minimize the total waiting time for everyone?

Input Format
The first line contains the integer n.

The second line contains n integers, where the i-th integer represents the time ti it takes for the i-th person to fill their bucket.

Output Format
Output an integer, representing the minimum total waiting time.

Data Range
1 ≤ n ≤ 105
1 ≤ ti ≤ 104

Input Example

7
3 6 1 4 2 5 7

Output Example

56

Comments

There are no comments at the moment.