Problem M
Dog Trouble
Yraglac is running a daycare service for dogs. He has
Yraglac has
As you know, dogs get impatient if they have to wait for
long periods of time. Therefore, Yraglac wants to minimize the
total amount of time that dogs spend waiting. More formally,
suppose
Input
The first line contains integers
Each of the next
Output
Output
Sample Input 1 | Sample Output 1 |
---|---|
2 3 2 100 10 100 1 10 |
0 |
Sample Input 2 | Sample Output 2 |
---|---|
3 3 100 20 30 10 90 80 99 90 98 |
12 |