Submit | All submissions | Best solutions | Back to list |
HS09BWB - Building with Blocks |
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.
Input
Input 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).
Output
Output 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.
Example
Input:
6 4
0 4 2 4 5 8
Output:
3 1
Added by: | Yandry Perez |
Date: | 2010-03-05 |
Time limit: | 1s-3.599s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | ADA95 ASM32 BASH BF C CSHARP CPP C99 CLPS LISP sbcl LISP clisp D FORTRAN HASK ICON ICK JAVA JS-RHINO LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON RUBY SCM guile SCM qobi ST TCL TEXT WHITESPACE |
Resource: | High School Programming League 2009/10 |