Pagini recente » Cod sursa (job #437017) | Cod sursa (job #3233935) | Cod sursa (job #2254685) | Cod sursa (job #2668188) | Cod sursa (job #2552627)
#include <bits/stdc++.h>
using namespace std;
ifstream in;
ofstream out;
vector <vector <int> > tree;
vector <int> gred;
int n;
int main()
{
in.open("scmax.in");
out.open("scmax.out");
in >> n;
int x, max1 = 1, poz = 1;
in >> x;
gred.push_back(x);
tree.push_back({ x });
for (int i = 2; i <= n; i++)
{
in >> x;
auto it = upper_bound(gred.begin(), gred.end(), x);
int poz1;
poz1 = distance(gred.begin(), it);
if (poz1 == 0)
{
gred.insert(gred.begin(), x);
tree.insert(tree.begin(),{ x });
}
else
{
if (poz1 < gred.size())
{
gred[poz1 - 1] = x;
tree[poz1 - 1].push_back(x);
if (tree[poz1 - 1][tree[poz1 - 1].size() - 1] == tree[poz1 - 1][tree[poz1 - 1].size() - 2])
tree[poz1 - 1].pop_back();
if (tree[poz1 - 1].size() > max1)
{
max1 = tree[poz1 - 1].size();
poz = poz1 - 1;
}
}
else
{
gred.push_back(x);
tree.push_back({ x });
}
}
//out << poz1 << " ";
}
out << max1<<endl;
for (int i = 0; i < tree[poz].size(); i++)
out << tree[poz][i] << " ";
//out << tree.size();
return 0;
}