## CCO '15 P1 - Hungry Fox

View as PDF

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

It's dinner time for your pet fox! His meal consists of crackers, with the cracker having a temperature of degrees Celsius. He also has a large dish of water, which has a temperature of degrees Celsius.

After taking an initial sip of water, your fox begins his meal. Every time he eats a cracker, its tastiness is equal to the absolute difference between its temperature, and the temperature of the last thing he ate or drank (be it the previous cracker he ate, or a sip of water, whichever he consumed most recently). He can drink some water whenever he wants. Depending on the order in which your fox eats and drinks, the total tastiness of the crackers consumed may vary. What are the minimum and maximum values it can have?

#### Input Specification

The first line contains two integers, () and (), representing the number of crackers and the water's temperature. On the next lines, there is one integer, ( for ), representing the temperature of the cracker.

For at least 30% of the marks for this problem, .

#### Output Specification

The output is one line containing two integers: the minimum and maximum total tastiness your fox can experience during his meal, respectively.

#### Sample Input

3 20
18
25
18

#### Output for Sample Input

7 16

#### Explanation of Output for Sample Input

To minimize the total tastiness, the fox might drink water, eat the first cracker, eat the third cracker, drink more water, and finally eat the second cracker. He will then experience temperatures of 20, 18, 18, 20, and 25 degrees Celsius, and the crackers will have tastiness values of .

To maximize the total tastiness, the fox might drink water, and then eat the crackers in order. He will then experience temperatures of 20, 18, 25, and 18 degrees Celsius, and the crackers will have tastiness values of .

• commented on Dec. 14, 2015, 10:29 p.m.

You know, it is pretty typical for the ccc to have pretty absurd numbers, but having a cracker is pretty insane. To compare, the core of our sun is measly . I must say that these are very hot crackers. Very, very hot crackers. I wonder what kind of fox this is.

• commented on Jan. 14, 2018, 4:23 p.m.

• commented on Dec. 14, 2015, 10:41 p.m.

• commented on Aug. 19, 2015, 6:16 p.m.
5 0
23 30 48 42 49
• commented on Aug. 19, 2015, 6:49 p.m. edited
49 195
• commented on Aug. 19, 2015, 6:53 p.m.

How did you get the 195?

• commented on Aug. 19, 2015, 6:56 p.m.

I plugged it into Andy's solution on my laptop

• commented on Aug. 19, 2015, 6:58 p.m. edited

Idk, I'm taking a drink of water after eating each cracker, so I reset the temperature back to 0.

This way I'm getting

Edit: Nevermind, it seems the solution is to take

49, 23, water, 30, water, 48, water 42 which gives 195.

• commented on Aug. 19, 2015, 7:00 p.m. edited

that isn't optimal

edit: proof: andy's solution gives a different answer