Pagini recente » Cod sursa (job #1754983) | Cod sursa (job #1295528) | Cod sursa (job #546821) | 2313123132 | Cod sursa (job #3194294)
#include <fstream>
using namespace std;
const int N = 1e5;
ifstream in("scmax.in");
ofstream out("scmax.out");
int v[N], l_max[N];
void refac_subsir(int poz, int val, int lungime)
{
if (lungime == 0)
{
return;
}
if (v[poz] <= val && l_max[poz] == lungime)
{
refac_subsir(poz - 1, v[poz] - 1, lungime - 1);
out << v[poz] << " ";
}
else
{
refac_subsir(poz - 1, val, lungime);
}
}
int main()
{
int n, poz_l_max = 0;
in >> n;
for (int i = 0; i < n; i++)
{
in >> v[i];
int lungime_i = 0;
for (int j = 0; j < i; j++)
{
if (v[j] < v[i])
{
lungime_i = max(lungime_i, l_max[j]);
}
}
l_max[i] = lungime_i + 1;
if (l_max[i] > l_max[poz_l_max])
{
poz_l_max = i;
}
}
out << l_max[poz_l_max] << "\n";
refac_subsir(poz_l_max, v[poz_l_max], l_max[poz_l_max]);
in.close();
out.close();
return 0;
}