Pagini recente » Cod sursa (job #727005) | Cod sursa (job #82628) | Cod sursa (job #2469394) | Cod sursa (job #2862326) | Cod sursa (job #986565)
Cod sursa(job #986565)
using namespace std;
#include<fstream>
#define Nmax 100005
ifstream eu("scmax.in");
ofstream tu("scmax.out");
int N,A[Nmax],best[Nmax],poz[Nmax],PozMa,maxim;
void read()
{
eu>>N;
for(int i=1;i<=N;i++)
eu>>A[i];
}
void solve()
{
for(int i=N;i>=1;i--)
{
best[i]=0;
for(int j=i+1;j<=N;j++)
if(A[i]<A[j]&&best[i]<best[j])
{
best[i]=best[j];
poz[i]=j;
}
best[i]++;
}
for(int i=1;i<=N;i++)
if(best[i]>maxim)
{
maxim=best[i];
PozMa=i;
}
}
int main()
{
read();
solve();
int i;
tu<<maxim<<"\n";
i=PozMa;
while(i)
{
tu<<A[i]<<" ";
i=poz[i];
}
return 0;
}