#P4801. Hungry Fox

    ID: 18045 Type: Default 1000ms 256MiB

Hungry Fox

Hungry Fox

Your pet fox is ready for dinner. His dinner consists of N cookies and a large bowl of water. The i-th cookie has a temperature of \(T_i\)°C, and the water is at a temperature of \(W\)°C.

When the fox takes a sip of water, he resets his "current food temperature" to \(W\). Whenever he eats a cookie, its "deliciousness" is defined as the absolute difference between its temperature and the temperature of the food (cookie or water) he had immediately before. He can drink water any number of times (the water supply is infinite) and may eat the cookies in any order.

The overall deliciousness is the sum of the deliciousness values of the cookies he eats. Your task is to compute the minimum and maximum total deliciousness that the fox can obtain.

Note: The fox can choose to drink water to reset the temperature at any time. In particular, he may choose to drink water before eating any cookie or between cookies.

The mathematical definitions are:

  • For a cookie eaten immediately after a food item with temperature \(x\), its deliciousness is \(|T_i - x|\).
  • You are allowed to insert water drinks (with temperature \(W\)) arbitrarily between cookies.

Determine the minimum and maximum possible sum of deliciousness values over all cookies.

inputFormat

The first line contains two integers \(N\) and \(W\) \( (1 \leq N \leq 2000)\) representing the number of cookies and the water temperature, respectively.

The second line contains \(N\) integers \(T_1, T_2, \ldots, T_N\) \( (0 \leq T_i \leq 10^9)\) representing the temperatures of the cookies.

outputFormat

Output two integers separated by a space: the minimum and maximum total deliciousness the fox can obtain.

sample

2 10
1 20
19 29