Pagini recente » Cod sursa (job #377355) | Cod sursa (job #2968500) | Cod sursa (job #94311) | Cod sursa (job #1289219) | Cod sursa (job #2063196)
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
ifstream fin("subsir2.in");
ofstream fout("subsir2.out");
long long i,j,n,a[5005],l[5005],nr,lmax,imax,nri,nrmin;
int main()
{
fin>>n;
for(i=1;i<=n;i++)
fin>>a[i];
for(i=n;i>=1;i--)
{
for(j=i+1;j<=n;j++)
if(a[i]<=a[j]&&l[i]<1+l[j])
l[i]=1+l[j];
if(l[i]==0)
l[i]=1;
if(l[i]>lmax)
lmax=l[i];
}
fout<<lmax<<'\n';
while(lmax>=1)
{
nr=1e9;
imax=nri;
for(i=imax+1;i<=n;i++)
if(l[i]==lmax)
if(nr>a[i])
{
nr=a[i];
nri=i;
}
fout<<nri<<" ";
lmax--;
}
return 0;
}