Pagini recente » Cod sursa (job #1627901) | Cod sursa (job #1900020) | Cod sursa (job #878134) | Cod sursa (job #1543438) | Cod sursa (job #2119141)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int n, v[100001], dp[100001], pred[100001];
void sb(int p)
{
if(pred[p]!=0)
sb(pred[p]);
out<<v[p]<<" ";
}
int main()
{
int lmax, pmax=1;
in>>n;
for(int i=1; i<=n; i++)
in>>v[i];
dp[1]=1;
for(int i=1; i<=n; i++)
{
lmax=0;
for(int j=0; j<n; j++)
if(v[j]<v[i] && dp[j]>lmax)
{
lmax=dp[j];
pred[i]=j;
}
dp[i]=1+lmax;
if(dp[i]>dp[pmax])
pmax=i;
}
out<<dp[pmax]<<"\n";
sb(pmax);
return 0;
}