Pagini recente » Cod sursa (job #2044445) | Autentificare | Cod sursa (job #203609) | Arhiva de probleme | Cod sursa (job #2267079)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int a[100005],poz[100005],n,best[100005],lgbest,i,j,pozitie,cine,s[100005];
int cauta (int x);
int main()
{
fin>>n;
for(i=1; i<=n; i++)
fin>>a[i];
best[++lgbest]=a[1];
for(i=2; i<=n; i++)
{
if(a[i]>best[lgbest])
{
best[++lgbest]=a[i];
poz[i]=lgbest;
}
else
{
pozitie=cauta(a[i]);
poz[i]=pozitie;
best[pozitie]=a[i];
}
}
fout<<lgbest<<'\n';
cine=lgbest;
for(i=n;i>=1;i--)
{
if(poz[i]==cine)
{
s[cine]=a[i];
cine--;
}
}
for(i=1;i<=lgbest;i++)
fout<<s[i]<<" ";
return 0;
}
int cauta (int x)
{
int mid,st ,dr;
st=1;
dr=lgbest+1;
while(dr-st>1)
{
mid=(st+dr)/2;
if(best[mid]>=x)
{
dr=mid;
}
else
st=mid;
}
return dr;
}