Pagini recente » Cod sursa (job #1957717) | Cod sursa (job #2485599) | Cod sursa (job #874162) | Cod sursa (job #2496866) | Cod sursa (job #2468020)
#include <iostream>
#include <fstream>
# define Nmax 100001
using namespace std;
long long n,v[Nmax],a[Nmax],i,w[Nmax],x,lung,lungmax,j,poz;
ifstream f("scmax.in");
ofstream g("scmax.out");
int caut(int x)
{
int s=1,d=lung,poz=100002;
bool gasit=true;
while(s<=d)
{
int mid=(s+d)/2;
if(x==a[mid]) {gasit=false;break;}
if(x<a[mid])
{
d=mid-1;
poz=min(mid,poz);
}
if(x>a[mid])s=mid+1;
}
if(gasit==false)poz=0;
return poz;
}
int main()
{
f>>n;
for(i=1; i<=n; i++) f>>v[i];
for(i=1; i<=n; i++)
{
poz=caut(v[i]);
if(poz==100002)
{
lung++;
a[lung]=v[i];
}
else {if(poz!=0)
{
a[poz]=v[i];
lung=poz;
}}
if(lung>lungmax)
{
lungmax=lung;
for(j=1; j<=lungmax; j++)w[j]=a[j];
}
}
g<<lungmax<<'\n';
for(j=1; j<=lungmax; j++) g<<w[j]<<" ";
}