Pagini recente » Cod sursa (job #1479660) | Cod sursa (job #1630130) | Cod sursa (job #2948455) | Cod sursa (job #1325257) | Cod sursa (job #1877182)
#include <iostream>
#include <fstream>
#define NMAX 100010
using namespace std;
ifstream f ("scmax.in");
ofstream g ("scmax.out");
int best[NMAX], v[NMAX], pre[NMAX], MAX, poz, n;
void Write(int x)
{
if (pre[x] != -1)
Write(pre[x]);
g<<v[x]<<' ';
}
int main()
{
f >> n;
for (int i = 0; i < n; i++)
{
f>>v[i];
int bestPoz = -1, Max = 0;
for (int j = 0; j < i; j++)
{
if (v[j] < v[i] && Max < best[j])
Max = best[j], bestPoz = j;
}
best[i] = Max + 1;
pre[i] = bestPoz;
if (best[i] > MAX)
MAX = best[i], poz = i;
}
g<<MAX<<'\n';
Write(poz);
return 0;
}