Pagini recente » Cod sursa (job #861436) | Cod sursa (job #1919851) | Cod sursa (job #764692) | Cod sursa (job #1230690) | Cod sursa (job #797039)
Cod sursa(job #797039)
#include<fstream>
using namespace std;
ifstream cin("subsir2.in");
ofstream cout("subsir2.out");
int p, n, i,j, minim, l[100005], urm[100005];
long long a[100005];
int main()
{
cin>>n;
minim=n;
urm[n]=-1;
l[n]=1; p=n;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=n;i>=1;i--)
{ urm[i]=-1;
l[i]=1;
for(j=n;j>i;j--)
if(a[i]<a[j] && l[i]<l[j]+1)
{ l[i]=l[j]+1;
urm[i]=j;
if(l[i]<=minim)
minim=l[i], p=i; }}
cout<<++minim<<"\n";
i=p;
while(i!=-1)
{ cout<<i<<" ";
i=urm[i];}
cout<<"\n";
return 0;
}