Pagini recente » Cod sursa (job #1530070) | Cod sursa (job #2284052) | Cod sursa (job #2381180) | Cod sursa (job #827144) | Cod sursa (job #2171513)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
long long n,v[100002],l[100002],w[100002],p,maxi,i;
int main()
{
fin>>n;
for(i=1;i<=n;i++)
fin>>v[i];
l[1]=1;
for(i=2;i<=n;i++)
{
maxi=0;
for(int j=1;j<=i-1;j++)
if(v[i]>v[j]&&l[j]>maxi)
maxi=l[j];
l[i]=1+maxi;
}
maxi=0;
for(i=1;i<=n;i++)
if(l[i]>maxi)
{
maxi=l[i];
p=i;
}
int j=1;
w[j]=v[p];
maxi--;
for(i=p-1;i>=1;i--)
if(v[p]>v[i]&&l[i]==maxi)
{
j++;
w[j]=i;
maxi--;
p=i;
}
fout<<j<<endl;
for(i=j;i>=1;i--)
fout<<w[i]<<' ';
}