(Over)due Diligence
You've found yourself in a bit of a rut, with many overdue assignments!
To fix this, you've created a list of all of the assignments you need to do, as well as an estimate for the amount of time in hours it will take to do each one.
The overdue penalty system is based on how long it has been since the due date, with a longer period resulting in higher grade deduction.
Can you figure out an order to do your assignments in to cause the least amount of total overdue hours for all of your assignments?
Input
The first line consists of an integer
, the number of assignments you have overdue.
The next lines each consist of a single integer
, the estimated amount of hours it will take to do the
th assignment.
Output
Output a single integer, the minimum amount of overdue hours that you can achieve after doing all of the overdue assignments.
Example
Input
3
4
10
4
Output
30
We can first do one of the 4-hour assignments and then submit it, adding 4 hours to our total overdue hours.
We can then do the other 4-hour assignment. Since we already took 4 hours on the first assignment, after doing this one it will have been overdue for 8 hours.
We then do the last assignment, which takes 10 hours. Since the previous assignments took a total of 8 hours, after doing this one it will have been overdue for 18 hours.
This gives us a total of hours. It can be shown that this is the minimum possible amount.
Comments