Pagini recente » Monitorul de evaluare | Cod sursa (job #2220277) | Cod sursa (job #2279479) | Cod sursa (job #1336353) | Cod sursa (job #1390667)
#include <iostream>
#include <fstream>
#define N 100005
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int a[N], b[N], p[N], n;
inline int Best(int i, int x)
{
int bst = 0, po = 0, j = i;
for (i-- ; i > 0; i--)
if (x > a[i] && b[i] > bst)
bst = b[i],
po = i;
p[j] = po;
return bst;
}
inline void Afis(int i)
{
if (i == 0) return;
Afis(p[i]);
fout << a[i] << " ";
}
int main()
{
int i, bb = 0, po = 0;
fin >> n;
for (i = 1; i <= n; i++)
fin >> a[i];
for (i = 1; i <= n; i++)
b[i] = 1 + Best(i, a[i]);
for (i = 1; i <= n; i++)
if (bb < b[i])
bb = b[i],
po = i;
fout << bb << "\n";
Afis(p[po]);
fout << a[po] << "\n";
return 0;
}