|
|||||||||||||||||||
|
SPOJ time: 2012-02-09 01:47:47 |
Building with BlocksProblem code: HS09BWB
Little John enjoys playing with blocks. He builds constructions along an imaginary straight line in such a way that we can describe his work by means of an integer N, the length of the line, and a list of N non-negative integers, the height of the building at each horizontal position. Today he would like to build a skyscraper. But, before that, he needs to make sure there are K consecutive positions of the same height, in order to use that section as a base for the skyscraper. You are to write a program that finds a section such that the number of block addition/removal operations needed to achieve such a flat base is minimized. You may assume Little John has an infinite number of blocks at his disposal. InputInput starts with two space separated integers: the length of the line (1<=N<=1000000) and the length of the required base (1<=K<=N). N space-separated non-negative integers follow, representing the height of the current building at each horizontal position (0<=Hi<=1000000). OutputOutput two space-separated integers O and P on a single line. The first one must correspond to the number of operations needed to make the base in the section starting at position P (the leftmost position is 0 and the rightmost is N-1). P must be as small as possible. ExampleInput:
|
||||||||||||||||||
| |||||||||||||||||||