Pagini recente » Cod sursa (job #452906) | Cod sursa (job #1541951) | concurs-mihai-patrascu-2013/clasament | Cod sursa (job #3158366) | Cod sursa (job #2529170)
#include <fstream>
#include <stack>
#include <algorithm>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
const int NMAX = 100001;
const int oo = 1e9;
int a[NMAX], b[NMAX], d[NMAX];
stack <int> st;
void lis(int n)
{
int maxi = 0;
for (int i = 1; i <= n; ++i)
{
d[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
if (d[i] > maxi) maxi = d[i];
b[d[i]] = a[i];
}
fout << maxi << "\n";
for (int i = n; i; --i)
if (d[i] == maxi)
{
st.push(a[i]);
maxi--;
}
while (!st.empty())
{
fout << st.top() << " ";
st.pop();
}
fout << "\n";
}
int main()
{
int n;
fin >> n;
for (int i = 1; i <= n; ++i)
{
fin >> a[i];
b[i] = oo;
d[i] = 0;
}
lis(n);
return 0;
}