#P2687. [USACO4.3] 逢低吸纳 Buy Low, Buy Lower

[USACO4.3] 逢低吸纳 Buy Low, Buy Lower

Description

“Buy on dips” is a successful tip for stock trading. If you want to be a successful investor, follow this tip: “Buy on dips, the lower the better.”

This means: every time you buy, the stock price must be lower than the price at your previous purchase. The more times you can buy under this rule, the better. See how many times at most you can buy following this rule.

You are given the price of the stock for each of NN consecutive days. You may buy once on any day, but the price at purchase must be lower than the price at your previous purchase. Write a program to find the maximum number of times you can buy.

For example, suppose the prices on some days are:

Day Price
11 6868
22 6969
33 5454
44 6464
55 6868
66 6464
77 7070
88 6767
99 7878
1010 6262
1111 9898
1212 8787

In this example, if each purchase price is lower than the previous one, you can buy at most 44 times. One valid way is as follows (there may be others):

Day Price
22 6969
55 6868
66 6464
1010 6262

Input Format

The first line: an integer NN, the number of days on which you can buy.

Then NN positive integers (possibly across multiple lines), where the ii-th integer is the stock price on day ii. Each integer does not exceed 23112^{31}-1.

Output Format

One line with two integers: the maximum number of days you can buy under the rule that each purchase price is lower than the previous one, and the number of purchase plans that achieve this maximum.

Two plans are different if and only if the sequences of purchased prices are different.

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

Hint

1N50001 \le N \le 5000.

Translated by ChatGPT 5