Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 28661 | Accepted: 12445 |
Description
Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.
Input
Output
Sample Input
7 1 7 3 5 9 4 8
Sample Output
4
Source
#include<iostream>
using namespace std;
int Arr[1001];
int main()
{
int N;
int i;
int temp;
cin>>N;
int top=0;
Arr[0]=-1;
for(i=0; i<N; i++)
{
cin>>temp;
if(temp>Arr[top])
Arr[++top]=temp;
else
{
int left=1;
int right=top;
int mid;
while(left<=right)
{
mid=(left+right)>>1;
if(temp>Arr[mid])
{
left=mid+1;
}
else
{
right=mid-1;
}
}
Arr[left]=temp;
}
}
cout<<top<<endl;
return 0;
}