Pagini recente » Cod sursa (job #1038440) | Cod sursa (job #3307601) | Cod sursa (job #994428) | Cod sursa (job #3328319) | Cod sursa (job #3324197)
#include <iostream>
#include <fstream>
#include <stack>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
stack <int> S;
int n,a[100001],best[100001],mx=0;
int main()
{
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>a[i];
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
{
if(best[j]>best[i] && a[j]<a[i])
best[i]=best[j];
}
best[i]++;
if(best[i]>mx)
{
mx=best[i];
}
}
fout<<mx<<"\n";
for(int i=n;i>0;i--)
{
if(best[i]==mx)
{
mx--;
S.push(a[i]);
}
}
while(!S.empty())
{
fout<<S.top()<<" ";
S.pop();
}
return 0;
}