Pagini recente » Cod sursa (job #1429115) | Cod sursa (job #2731895) | Cod sursa (job #1783637) | Cod sursa (job #2416761) | Cod sursa (job #1583715)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
const int Nmax = 100005;
int n, DP[Nmax], a[Nmax], Succ[Nmax], Max, pos;
void Read()
{
f>>n;
for(int i = 1; i <= n; i++) f>>a[i];
}
void Solve()
{
for(int i = n; i > 0; i--)
{
DP[i] = 1;
for(int j = i+1; j <= n; j++)
{
if(a[i] < a[j] && DP[i] < DP[j]+1)
{
DP[i] = DP[j]+1;
Succ[i] = j;
}
}
if(Max < DP[i])
{
Max = DP[i];
pos = i;
}
}
}
void Print()
{
g<<Max<<'\n';
while(pos) g<<a[pos]<<' ', pos = Succ[pos];
}
int main()
{
Read();
Solve();
Print();
return 0;
}