#P5186. FENCE PAINTING

    ID: 18422 Type: Default 1000ms 256MiB

FENCE PAINTING

FENCE PAINTING

This is a translation of a problem originally taken from [COCI 2010.02](http://hsin.hr/coci/archive/2009_2010/). In this problem, Matija has a fence consisting of N wooden boards numbered from \(1\) to \(N\). The height of the \(i\)th board is given by \(h_i\) (in centimeters), and every board is \(1\) cm wide.

Matija owns a roller brush of fixed width \(X\) cm. When using the roller brush, he must ensure the brush is placed horizontally so that it completely touches the boards – it cannot partly contact the fence. In each roller stroke, he chooses a contiguous block of exactly \(X\) boards. Then he uses the roller brush to paint from the bottom upward, stopping when he reaches the (current) height of the shortest board in that block. (Any board—because of its possibly greater height—may still have an unpainted portion above.)

The parts of the fence that the roller cannot cover (due to the restriction imposed by the shortest board in a chosen block) must be painted manually with a toothbrush. Matija wants to plan his painting so that the total area painted manually (in square centimeters) is minimized. Moreover, among all strategies which minimize the manual painting area, he wishes to use the roller brush as few times as possible.

Your task is to compute two numbers: the minimum total manual area (in cm2) that needs to be painted with a toothbrush, and the minimum number of roller brush strokes required (subject to that manual area being minimized).

Note on the roller stroke: When a roller stroke is applied to a block of \(X\) boards whose current unpainted heights are \(a_i\), the stroke paints a vertical distance \(d = \min_{\text{in block}}\,a_i\) on every board of that block, thereby covering an area of \(d\times X\) cm2. You may apply strokes in any order; however, the brush must always cover exactly \(X\) consecutive boards that all still have some unpainted area. The strategy must be chosen to maximize the area painted by the roller (and hence minimize the manual area), and, if multiple strategies yield the same maximal roller‐painted area, to minimize the number of strokes used.

The problem guarantees that a solution exists and that the input is such that optimal decisions can be made by a greedy‐simulation algorithm. For the purpose of this problem, you may assume that \(N\) and the heights \(h_i\) are small enough that a simulation approach (iteratively applying a roller stroke with the maximum feasible vertical painting in some valid block) will run in time.

inputFormat

The first line contains two integers \(N\) and \(X\) ( 1 ≤ N ≤ 100, 1 ≤ X ≤ N), where \(N\) is the number of boards and \(X\) is the roller brush width (in cm).
The second line contains \(N\) positive integers \(h_1, h_2, \dots, h_N\) (each \(h_i\) is at most 100), denoting the height of each board (in cm).

outputFormat

Output two integers separated by a space. The first integer is the minimum total manual area (in cm2) that must be painted by toothbrush, and the second is the minimum number of roller strokes needed to achieve that manual area.

sample

5 3
3 1 3 1 3
5 2

</p>