Submit | All submissions | Best solutions | Back to list |
CODERE3 - Coder Express 3!! |
Mr Durgeshwara was very impressed by Rahul. But now he was in trouble. He has already fixed his daughter's marriage with Thangabali who was the best coder of his town. He got an idea and arranged a contest between Rahul and Thangabali. They have to solve a problem at the same time and whoever solves first will marry Meenamma. Rahul was not such a good coder and was also getting help from Meenamma. Your task is to help Thangabali to solve the problem to create a twist in story.
The problem was that there are large number of building in the town which are of different heights and all the building are in a single line.
You have to find the maximum possible length of the subsequences of buildings which are possible which are first increasing in heights and then decreasing! Please Note: the heights of the building in the subsequences should be strictly increasing and then strictly decreasing.
Input
First line contains an integer T (1 ≤ T ≤ 100) that represents the number of test cases. Then follows the T containing the integer N (1 ≤ N ≤ 1000) specifying the total number of elements and the next line contains the N integers A1, A2, A3 ... An (1 ≤ Ai ≤ 1000)
Output
For each test case, print only one line, the maximum length of such sequence.
Example
Input: 2 10 1 3 5 6 4 8 4 3 2 1 6 8 6 3 4 2 1 Output: 9 5
Explanation
For the first test case the subsequence is : 1 3 5 6 8 4 3 2 1. For the second test case it is : 8 6 4 2 1
Added by: | Rajesh Kumar |
Date: | 2013-09-01 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | AASF - ABV-IIITM PC-01-9-2013 |
hide comments
|
||||||||
2015-07-12 20:27:06 scyth3r
use DP twice.... 1. Longest increasing sub-sequence 2. Longest decreasing sub-sequence Find max Last edit: 2015-07-12 20:29:05 |
||||||||
2015-07-12 12:13:33 scyth3r
no Python submissions..... :(:(:( |
||||||||
2015-07-10 13:29:23 :.Mohib.:
Nice one!! +1 for srk ;) |
||||||||
2015-06-15 20:14:13 Rishit Sanmukhani
Would have been better if n = 10^5. In that case we have to use 0(nlogn) LIS solution. PS: Careful of the point that it is strictly increasing and then strictly decreasing. This implies at most one maximum. |
||||||||
2015-02-03 21:22:22 paras meena
*********!!! O(2 * N^2) TLE :/ And O(N^2 + N^2) AC ya same thing o.O Edit(Francky) : Please use family friendly language. Last edit: 2015-02-03 22:57:08 |
||||||||
2014-05-27 07:57:05 P_Quantum
Easy one.!! |
||||||||
2014-01-17 09:22:36 Abhinav Gupta
AC!!!..O(n^2) will work easily...Kindly increase N to > 10^5 Last edit: 2014-01-17 09:22:54 |
||||||||
2014-01-11 21:16:07 anurag garg
AC with O(n^2) |
||||||||
2013-12-26 16:25:51 nj@iiita
why i am getting WA, can anybody give me test case... |
||||||||
2013-12-15 15:43:09 lokesh gopu
Yeah even my n^2 algorithm passed.. :) |