Pagini recente » Cod sursa (job #3213052) | Cod sursa (job #2290718) | Cod sursa (job #318912) | Cod sursa (job #1108693) | Cod sursa (job #2796731)
#include <fstream>
#include <cstring>
#include <vector>
using namespace std;
ifstream cin("scmax.in");
ofstream cout("scmax.out");
vector<int> rez, aux ;
int v[100009], pozaux[100009] ;
void afis(int f, int n)
{
while(n > 0)
{
///cout << pozaux[n] << " " << f << endl ;
if(pozaux[n] == f)
rez.push_back(v[n]), f -- ;
n -- ;
}
for(int f = rez.size() - 1 ; f >= 0 ; f --)
cout << rez[f] << " " ;
}
int main()
{
int n ;
cin >> n ;
for(int f = 1 ; f <= n ; f ++)
cin >> v[f] ;
for(int f = 1 ; f <= n ; f ++)
if(!aux.size() || v[f] > aux.back())
aux.push_back(v[f]), pozaux[f] = aux.size() - 1 ;
else
{
int poz = (int)(lower_bound(aux.begin(), aux.end(), v[f]) - aux.begin()) ;
aux[poz] = v[f] ;
pozaux[f] = poz ;
}
cout << aux.size() << endl ;
afis(aux.size() - 1, n) ;
return 0;
}