Pagini recente » Cod sursa (job #1208070) | Cod sursa (job #2730591) | Cod sursa (job #2436202) | Cod sursa (job #1823207) | Cod sursa (job #883683)
Cod sursa(job #883683)
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int n,v[100001],bst[100001],pref[100001],mx,p;
void citire()
{
int i;
f>>n;
for(i=1;i<=n;i++)
f>>v[i];
}
int main()
{
int i,j;
citire();
bst[n]=1;
for(i=n-1;i>0;i--)
{
bst[i]=1;
for(j=i+1;j<=n;j++)
{
if(v[i]<v[j] && bst[i]<bst[j]+1)
{
bst[i]=bst[j]+1;
pref[i]=j;
if(bst[i]>mx)
{
mx=bst[i];
p=i;
}
}
}
}
g<<mx<<endl;
while(p)
{
g<<v[p]<<" ";
p=pref[p];
}
return 0;
}