Pagini recente » Cod sursa (job #984074) | Cod sursa (job #401711) | Cod sursa (job #3290567) | Cod sursa (job #1620096) | Cod sursa (job #2315496)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int main()
{
int n, poz, maxim = 0;
in.sync_with_stdio(false);
in >> n;
vector<int> v(n + 1);
vector<int> best(n + 1);
vector<int> next(n + 1);
for (int i = 1; i <= n; i++)
in >> v[i];
for (int i = n - 1; i >= 1; i--)
for (int j = i + 1; j <= n; j++)
if (v[i] < v[j])
if (best[i] < best[j] + 1)
best[i] = best[j] + 1, next[i] = j;
for (int i = 1; i <= n; i++)
if (best[i] > maxim)
maxim = best[i], poz = i;
out << maxim + 1 << '\n';
while (poz)
{
out << v[poz] << ' ';
poz = next[poz];
}
return 0;
}