LIS CODE WITH  MULTISET


if  we  required  repeated  elements we use upper_bound(s.begin(),s.end(),g)   if(it!=s.end()) then erase(it);



if repaeated elements are not required then we use---->>>>  s.find(g);  it++;  if(it!=s.end()) then erase(it);


#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
    int n,g;
    multiset<int> s;
    multiset<int>::iterator it;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>g;
        s.insert(g);
        it = upper_bound(s.begin(), s.end(), g);
        if(it!=s.end())
        s.erase(it);
    }
    cout<<s.size()<<endl;
    return 0;
}

Comments

Popular posts from this blog

Getting Started With MEAN App Development with AngularJs , ExpressJs , NodeJs and MongoDB.

B. Dreamoon and WiFi :calculate no. of ways : recursive solution (branch and bound )

A. Dreamoon and Stairs : minimum steps to reach : recursion solution.