問題一覧 > 通常問題

No.209 Longest Mountain Subsequence

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 64 MB / 標準ジャッジ問題
タグ : / 解いたユーザー数 78
作問者 : LayCurse
5 ProblemId : 368 / 出題時の順位表 / 自分の提出
問題文最終更新日: 2015-11-14 17:48:09

Statement

Find the maximum length of the subsequence {Bi}i=1k of the given sequence {Ai}i=1N such that
1jk,B1<B2<<Bj>>Bk1>Bk|B1B2|<|B2B3|<<|Bj1Bj||BjBj+1|>|Bj+1Bj+2|>>|Bk1Bk|.


Fig. 1. The view from Nihondaira (Dec. 27th, 2014)

Input

The first line of the input contains an integer T, denoting the number of test cases.
Then T test cases follow, and the format of each test case is as follows:
N
A1 A2  AN

1T100
1N100
0Ak1000000000=109
All variables are non-negative integers.

Output

For each test cases, print the maximum length of B.

Sample

Input
4
5
1 2 3 4 5
9
1 2 4 8 100 8 4 2 1
9
1 7 5 3 1 6 3 9 1
1
1
Output
3
9
5
1

In the first case, B=1,2,4 is one of the desired subsequence, and another is B=1,2,5.
In the second case, B=A is a valid subsequence.
In the third case, B=1,3,6,3,1 has length =5.
In the fourth case, the sequence consisted of only one element is also valid.

補足: は存在するという意味, は「かつ(and)」を意味します.
だんだん大きくなって,だんだん小さくなる列で,最大値に近づくほど差が急になるものです.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。