Pagini recente » Cod sursa (job #3295226) | Cod sursa (job #2678859) | Cod sursa (job #2405476) | Cod sursa (job #2405480) | Cod sursa (job #3326107)
#include <fstream>
using namespace std;
int main()
{
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int a[100001], lung[100001], poz[100001];
int n, i, j;
fin >> n;
for (i = 1; i <= n; i++)
fin >> a[i];
lung[n] = 1;
poz[n] = -1;
for (i = n - 1; i >= 1; i--)
{
lung[i] = 1;
poz[i] = -1;
for (j = n; j > i; j--)
if (a[i] < a[j] && lung[i] < lung[j] + 1)
{
lung[i] = lung[j] + 1;
poz[i] = j;
}
}
int maxim = -1, pozitie = -1;
for (i = 1; i <= n; i++)
if (lung[i] > maxim)
{
maxim = lung[i];
pozitie = i;
}
fout << maxim << "\n";
while (pozitie != -1)
{
fout << a[pozitie] << " ";
pozitie = poz[pozitie];
}
return 0;
}