Pagini recente » Cod sursa (job #2304847) | Cod sursa (job #1476196) | Cod sursa (job #1251378) | Cod sursa (job #742413) | Cod sursa (job #1787253)
#include<fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int n,v[100001],sol[100001],p,ns,a[100001];
int main()
{
f>>n;
for(int i=1;i<=n;++i)
f>>v[i];
sol[n]=1;
ns=1;
p=n;
for(int i=n-1;i>=1;--i)
{
int w=1;
for(int j=i+1;j<=n;++j)
if(sol[j]>w && v[j]>v[i])
w=sol[j];
sol[i]=w+1;
if(ns<w+1)
{ns=w+1;p=i;}
}
g<<ns<<'\n'<<v[p]<<' ';
int k=p;
p++;ns--;
for(int i=p;i<=n;++i)
if(sol[i]==ns && v[i]>v[k])
{
g<<v[i]<<' ';
k=i;
ns--;
}
g.close();
return 0;
}