Pagini recente » Cod sursa (job #473107) | Cod sursa (job #724016) | Cod sursa (job #2404059) | Cod sursa (job #1447954) | Cod sursa (job #1042394)
#include <iostream>
#include <fstream>
#define N_MAX 100000
#define INF -2000000
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int n, v[N_MAX], best[N_MAX], pre[N_MAX], strt;
int mx = best[0];
int v_max(int c)
{
int vmax = INF, pmax = -1;
for(int i = 0; i < c; i++)
if(v[i] < v[c] && best[i] > vmax)
{
vmax = best[i];
pmax = i;
}
if(pmax != -1) pre[c] = pmax;
if(vmax == INF) return 0;
return vmax;
}
void scm()
{
best[0] = 1;
for(int i = 1; i < n; i++)
{
best[i] = v_max(i) + 1;
if(best[i] > mx)
{
mx = best[i];
strt = i;
}
}
}
void afisare(int x)
{
if(pre[x] != -1)
afisare(pre[x]);
out << v[x] << " ";
}
int main()
{
in >> n;
for(int i = 0; i < n; i++)
{
in >> v[i];
pre[i] = -1;
}
scm();
out << mx << '\n';
afisare(strt);
return 0;
}