Cod sursa(job #2303634)
| Utilizator | Data | 16 decembrie 2018 17:41:53 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n,nmax,k,i,st,dr,m;
int a[100005],dp[100005], t[100005];
int afis(int x)
{
if(x){
afis(t[x]);
fout<<a[x]<<' ';
}
}
int main()
{
fin>>n; for(i=1;i<=n;i++)fin>>a[i];
k=dp[1]=1;
for(i=2;i<=n;i++)
{
st=1;dr=k;m=0;
while(st<=dr) {
m=(st+dr)/2;
if(a[dp[m]]<a[i])st=m+1; else dr=m-1;
}
if(st>k) k++;
dp[st]=i;
t[i]=dp[st-1];
}
fout<<k<<'\n';
afis(dp[k]);
return 0;
}
