Tower of Books
The Library of Babel is a short story by Jorge Luis Borges that imagines a library containing all possible 410-page books in the entire universe. The name is derived from the Tower of Babel, a biblical story where people tried to build a tower that would reach the sky. This gives you an idea.
While you can't build a tower to reach the sky, you could still try to make a tall tower out of books. You head over to the library and find long shelves filled with books. You logically conclude that it is best not to put larger books on top of smaller books, so whenever a larger book is encountered, you'll remove all the smaller books beneath it and continue going through the books on the shelves. There isn't much time before the library closes, so you get no time to sort through the books — you'll have to start stacking now!
Input
The first line contains an integer , the number of books on the shelves.
The next lines contain the size of the books
. The books are in the order in which you pick them up to use.
Output
Output the final height of your book tower, which is measured by the number of books in the tower.
Example
Input 1
5
50
30
40
20
10
Output 1
4
We put the book with size at the bottom, then the book with size
. However, since the next book which has a size of
is larger than
, we remove the book with size
. We can add the rest of the books without them being larger than the books underneath it. This results in a book tower of height
.
Input 2
4
100
101
102
103
Output 2
1
The last book that you grab (which has a size of ) is larger than the previous books you've grabbed. This means that the tower only has one book.
Comments