-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCODERE3.cpp
62 lines (55 loc) · 843 Bytes
/
CODERE3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// PRATEEK CHANDAN
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <list>
using namespace std;
int main()
{
int n,t;
cin>>t;
while(t--)
{
cin>>n;
int a[n],ma[n],mi[n];
for (int i = 0; i < n; i++)
{
cin>>a[i];
ma[i]=0;
mi[i]=0;
}
for (int i = 0; i < n; i++)
{
for (int j = i-1; j >=0 ; j--)
{
if(a[j]<a[i]){
if(mi[j]+1 > mi[i])
mi[i]=mi[j]+1;
}
}
}
for (int i = n-1; i >= 0; i--)
{
for (int j = i+1; j <n ; j++)
{
if(a[j]<a[i]){
if(ma[j]+1 > ma[i])
ma[i]=ma[j]+1;
}
}
}
int maxi=0;
for (int i = 0; i < n; i++)
{
//cout<<ma[i]<<":"<<mi[i]<<" ";
if((ma[i]+mi[i]+1)>maxi)
maxi=ma[i]+mi[i]+1;
}
cout<<maxi<<endl;
}
return 0;
}