Ocean View (Small)
InterviewTime limit5sMemory limit512 MB
Destroy the fewest houses so the heights of the houses that remain strictly increase from the lake eastward.
- Level
Easy3 of 10
- Topics
- Brute force, Array
- Solved
- No attempts yet
Problem
Ocean View is a town on the edge of a small lake. The town has a single street, running west from the lake toward a hill in the east. Every house sits on one side of that street, numbered from 1 at the lakeside end up to at the foot of the hill.
Every resident wants to see the lake, but a house in front can block the view of a house behind it. House blocks the view of house when and the height of house is greater than or equal to the height of house .
The ruler of the town has decided to destroy some houses so that every remaining house has a view of the lake. Destroying too many houses would anger the residents, so the ruler wants to destroy as few as possible.
Find the smallest number of houses that must be destroyed so that every remaining house sees the lake.
Input
The first line contains the number of test cases . Then test cases follow, each on two lines. The first line contains the number of houses . The next line lists the height of each house from west to east, separated by single spaces.
Limits
- Each height is an integer between and , inclusive.
- The answer is always at most .
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from 1 and is the minimum number of houses that must be destroyed.
Hint
The first sample case has several answers. Keep house 1 and destroy any two of the remaining three. Destroying only the tallest house is not enough, because house 3 still blocks the view of house 4.
The second case needs no destruction at all. Every resident already sees the lake.
The third case leaves exactly one house standing. It does not matter which one.
In the fourth case, only the resident of the shortest house loses the view. Destroying the three houses west of it also works, but destroying that single house is better.