#P16738. [GKS 2019 #F] Flattening
[GKS 2019 #F] Flattening
Problem Description
Blotch has built a wall. The wall is made up of sections, numbered from to from left to right. Since he had built the wall in a hurry, not all the sections are of the same height. The -th section of wall is metres tall.
Blotch would like to fix his wall by rebuilding some of the sections. Blotch can set the height of each section he rebuilds to any height he chooses.
Blotch will be happy if the number of indices () where is not more than .
What is the fewest sections of the wall Blotch needs to rebuild so that he will be happy?
Input Format
The first line of the input gives the number of test cases, . test cases follow. Each test case begins with a line containing the two integers and , the number of sections of wall and the maximum number of changes in height between adjacent sections, respectively.
The second line contains integers. The -th integer is , the height of the -th section of wall.
Output Format
For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the fewest sections that Blotch has to rebuild so that he will be happy.
4
8 2
300 100 300 300 200 100 800 500
5 3
100 100 100 100 3
7 3
10 20 40 10 10 30 30
10 2
30 30 60 60 90 90 60 60 30 30
Case #1: 3
Case #2: 0
Case #3: 1
Case #4: 2
Hint
In the first sample case, there are sections of wall, and Blotch will be happy if there are at most changes in height between adjacent sections. Blotch can:
- rebuild the 2nd section of wall to have height 300,
- rebuild the 6th section of wall to have height 200, and
- rebuild the 8th section of wall to have height 800.
This produces a wall with sections of height and 800, which makes Blotch happy.
In the second sample case, there are sections of wall, and Blotch will be happy if there are at most changes in height between adjacent sections. Blotch is already happy with this wall, so he does not need to rebuild any sections.
In the third sample case, there are sections of wall, and Blotch will be happy if there are at most changes in height between adjacent sections. Blotch can:
- rebuild the 2nd section of wall to have height 10.
This produces a wall with sections of height and which makes Blotch happy.
In the fourth sample case, there are sections of wall, and Blotch will be happy if there are at most changes in height between adjacent sections. Blotch can:
- rebuild the 5th section of wall to have height 60, and
- rebuild the 6th section of wall to have height 60.
This produces a wall with sections of height which makes Blotch happy.
Limits
.
, for all i.
.
Test set 1 (Visible)
.
Test set 2 (Hidden)
.