#P12930. [USACO4.3] 逢低吸纳 Buy Low, Buy Lower 加强版
[USACO4.3] 逢低吸纳 Buy Low, Buy Lower 加强版
Background
An enhanced version of P2687. In this problem, , and the number of plans needs to be taken modulo .
Problem Description
“Buy low” is a successful rule of thumb in stock trading. If you want to become a successful investor, you should follow this rule: “buy low, and the lower it gets, the more you buy.”
This means: each time you buy a stock, the price must be lower than the price when you bought last time. The more times you can buy under this rule, the better. Find the maximum number of times you can buy under this rule.
Given the stock prices over consecutive days, you may buy at most once on any day, but the price when you buy must be lower than the price when you bought previously. Write a program to compute the maximum number of times you can buy, and the number of optimal plans modulo .
For example, the stock prices on some days are:
| Day | Price |
|---|---|
In this example, if each time you buy the stock the price is lower than the last time, you can buy at most times. One possible way to buy is (there may be other ways):
| Day | Price |
|---|---|
Input Format
Line : an integer , the number of days on which you can buy stocks.
The following lines contain non-negative integers (possibly across multiple lines). The -th positive integer represents the stock price on day . These non-negative integers will not exceed .
Output Format
Output one line with two integers: the maximum number of days on which you can buy stocks while ensuring that each purchase price is lower than the previous purchase price, and the number of purchase plans that achieve this maximum, taken modulo .
Two plans are different if and only if the sequences of purchased stock prices in the two plans are different.
12
68 69 54 64 68 64 70 67
78 62 98 87
4 2
Hint
。
Translated by ChatGPT 5