#P2687. Stock Purchase Strategy: Buy at Lower Prices

    ID: 15952 Type: Default 1000ms 256MiB

Stock Purchase Strategy: Buy at Lower Prices

Stock Purchase Strategy: Buy at Lower Prices

The key to success in stock trading, as the old saying goes, is to buy low. In this problem, you are given the stock prices for N consecutive days. You can buy a stock on any day you want; however, when you buy, the price on that day must be strictly lower than the price on the day you made your previous purchase. Your task is to determine the maximum number of times you can purchase stocks following this rule.

Note: The first purchase can be made on any day. For every subsequent purchase, the price must be lower than the last price at which you bought a stock.

For example, consider the following table of prices:

DayPrice
168
269
354
464
568
664
770
867
978
1062
1198
1287

One possible way to make the purchases is:

DayPrice
269
568
664
1062

Here, you are able to purchase stocks 4 times following the rule. Your task is to write a program that calculates the maximum number of purchases possible given the stock prices over N days.

The condition for each purchase (after the first) can be formally written in LaTeX as follows:

$$price_{i} > price_{j} \quad\text{for\ each\ consecutive\ purchase\ where}\ i < j. $$

inputFormat

The first line contains an integer N indicating the number of days.

The second line contains N space-separated integers representing the stock prices on each day.

outputFormat

Output a single integer representing the maximum number of times you can purchase stocks by following the rule that each purchase (after the first) must be made at a strictly lower price than the previous purchase.

sample

12
68 69 54 64 68 64 70 67 78 62 98 87
4