## COCI '09 Contest 4 #4 Ograda

View as PDF

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

Problem types

Matija needs to paint his old fence. The fence is made from planks, each cm in width and varying in height. To do this easy and fast, he bought himself a Super Paint Roller Deluxe. The paint roller is cm wide. The Super Paint Roller Deluxe model comes with a catch, however. Matija must at all times touch the planks with full width of the roller, otherwise paint drops all around and stains everything. Also, the roller must always be parallel to the ground to prevent leakage. This means that in order for Matija to use the roller safely, he needs to select planks, and paint them from bottom to the top of the lowest plank in one swoop. Then he selects some other planks, paints them and so on.

This leaves parts of some planks unpainted. Matija will have to paint such parts with a toothbrush. This is obviously quite tedious so he asked you to help him paint as much as possible using the Super Paint Roller Deluxe. Since there is more than one way to do this he is also interested in the painting that requires the minimal number of swoops.

#### Input Specification

The first line of input contains two integers , number of planks, and , width of the Super Paint Roller. Width of the Super Paint Roller will not exceed the width of the fence.

The second line of input contains positive integers, smaller than , heights of planks in the fence.

Note: If only one of the output numbers is correct, you will receive of points for that test case. You must always follow the output format to the letter, even if you do not calculate both numbers. In such case, you may output any integer in place of the number you did not calculate.

#### Output Specification

The first line of output should contain the smallest possible area Matija will have to paint manually.

The second line of output should contain the smallest number of swoops needed.

5 3
5 3 4 4 5

3
2

#### Explanation for Sample Output 1

Matija needs two swoops with his roller - one to paint planks , and to the height of cm, the other to paint planks , and to the height of cm. Note that cm ( cm on plank and cm on plank ) are left unpainted. Also, cm on plank are painted over twice, but that's OK.

#### Sample Input 2

10 3
3 3 3 3 3 3 3 3 3 3

0
4

7 4
1 2 3 4 3 2 1

4
4