Box Stacking

0

0 votes
Problem

Imagine you are a warehouse staff, your job is to stack boxes.

The conveyor belt puts out a bunch of boxes in a certain order. Each box has a size S. To stack a box on top of another, the box must be smaller than the other.

Each time a box comes out of the conveyor belt, you can either let it pass or add it to your stack. You cannot go back and get a box that has passed. You can throw away your current stack and start a new stack with the new box, but you can't add boxes from your old stack to the new stack.

You want to find out how the maximum height you to stack the boxes, given that you know the order of boxes that are coming out.

 

Input:

Integers separated by comma representing the size of boxes.

 

Output:

The maximum height of boxes you can stack.

 

Constraints:

1 <= S <= 100

1 <= number of boxes <= 1000

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

The order of boxes coming out is of size: 4, 9, 10, 6, 1, 4, 2, 3.

The highest you can stack the boxes are in order of 10, 6, 4, 2.

The max height is 4.

Editor Image

?