Pagini recente » Cod sursa (job #3269610) | Cod sursa (job #3233495) | Cod sursa (job #2226662) | Cod sursa (job #2042432) | Cod sursa (job #2566619)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <deque>
using namespace std;
ifstream f("scmax.in");;
ofstream g("scmax.out");
int n, i, j, a[100010], k;
deque<int > b;
int main()
{
f >> n;
for (i = 1; i <= n; ++i)
{
f >> a[i];
if (!b.empty())
{
if (a[i] > b.back())
b.push_back(a[i]);
else
{
k = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
if (k > 0)
b[k] = a[i];
}
}
else
b.push_back(a[i]);
}
g << b.size() << '\n';
while (!b.empty())
{
g << b.front() << " ";
b.pop_front();
}
return 0;
}