#abc262g. G - LIS with Stack
G - LIS with Stack
Score : points
问题描述
存在一个空的序列 和一个空栈 。同时,你得到一个整数序列 ,其长度为 。
对于每个 (按照这个顺序),Takahashi 将执行以下操作之一:
- 将整数 移动到 的顶部。
- 从 中丢弃整数 。
另外,当 不为空时,Takahashi 可以执行以下操作:
- 将 顶部的整数移动到 的尾部。
最终 的得分定义如下:
- 如果 是非递减的,即对于所有整数 ,满足 (其中 ),则得分是 (其中 表示 中项的数量)。
- 如果 不是非递减的,则得分是 。
找出可能的最大得分。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is an empty sequence and an empty stack . Also, you are given an integer sequence of length .
For each in this order, Takahashi will do one of the following operations:
- Move the integer onto the top of .
- Discard the integer from .
Additionally, Takahashi may do the following operation whenever is not empty:
- Move the integer at the top of to the tail of .
The score of the final is defined as follows.
- If is non-decreasing, i.e. if holds for all integer , where , then the score is (where denotes the number of terms in ).
- If is not non-decreasing, then the score is .
Find the maximum possible score.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
7
1 2 3 4 1 2 3
Sample Output 1
5
The following operations make the final equal , for a score of .
- Move onto the top of .
- Move at the top of to the tail of .
- Move onto the top of .
- Discard .
- Move onto the top of .
- Move onto the top of .
- Move at the top of to the tail of .
- Move onto the top of .
- Move at the top of to the tail of .
- Move onto the top of .
- Move at the top of to the tail of .
- Move at the top of to the tail of .
We cannot make the score or greater, so the maximum possible score is .
Sample Input 2
10
1 1 1 1 1 1 1 1 1 1
Sample Output 2
10
update @ 2024/3/10 11:06:47