Pagini recente » Cod sursa (job #574944) | Cod sursa (job #2495969) | Cod sursa (job #3172844) | Cod sursa (job #3162648) | Cod sursa (job #1098372)
#include <fstream>
#define NMAX 100001
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int a[NMAX],best[NMAX],poz[NMAX],n,sol[NMAX];
void citire();
int main()
{
int i,pozcrt=1,st,dr,mijl,x;
citire();
for (i=1; i<=n; i++)
{
if (a[i]>best[pozcrt-1])
{
best[pozcrt]=a[i];
poz[i]=pozcrt++;
}
else
{
st=1; dr=pozcrt-1;
while (st<dr)
{
mijl=(st+dr)/2;
if (best[mijl]<a[i]) st=mijl+1;
else dr=mijl-1;
}
best[st]=a[i];
poz[i]=st;
}
}
x=pozcrt;
fout<<pozcrt-1<<'\n';
for (i=n; i>=1; i--)
{
if (poz[i]==pozcrt-1) sol[pozcrt--]=a[i];
}
for (i=2; i<=x; i++) fout<<sol[i]<<' ';
return 0;
}
void citire()
{
int i;
fin>>n;
for (i=1; i<=n; i++) fin>>a[i];
}