Hungry Fox
Time limit2sMemory limit512 MB
Given cracker temperatures and a starting water temperature, order eating and water sips to minimize and maximize the total of absolute differences.
Problem
It is dinner time for your pet fox. His meal consists of crackers, and the -th cracker has a temperature of degrees Celsius. He also has a large dish of water whose temperature is degrees Celsius.
After taking an initial sip of water, your fox begins his meal. Every time he eats a cracker, its tastiness is the absolute difference between its temperature and the temperature of the last thing he ate or drank. That last thing is either the previous cracker he ate or a sip of water, whichever he consumed most recently. He can drink some water whenever he wants, and he can eat the crackers in any order.
Depending on the order in which your fox eats and drinks, the total tastiness of the crackers he consumes may vary. Find the minimum and the maximum value of this total.
Input
The first line contains two integers and (, ): the number of crackers and the temperature of the water.
Each of the next lines contains one integer (), the temperature of the -th cracker.
Output
Print one line with two integers separated by a space: the minimum and the maximum total tastiness your fox can experience during his meal, in that order.