Pagini recente » Cod sursa (job #2729925) | Cod sursa (job #18625) | Cod sursa (job #3032476) | Cod sursa (job #2109400)
#include <fstream>
using namespace std;
ifstream cin("scmax.in");
ofstream cout("scmax.out");
const int MAX = 1e5 + 1;
int n, v[MAX], lg[MAX], pred[MAX], lgmax;
int main()
{
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> v[i];
}
for(int i = 1; i <= n; ++i) {
int st = 1, dr = lgmax;
while(st <= dr) {
int mij = (st + dr) / 2;
if(v[ lg[mij] ] < v[i]) {
st = mij + 1;
} else {
dr = mij - 1;
}
}
if(st > lgmax) {
++lgmax;
}
lg[st] = i;
pred[i] = lg[st - 1];
}
cout << lgmax << '\n';
int poz = lgmax - 1;
int cur = lg[lgmax];
while(cur > 0) {
lg[poz] = pred[cur];
cur = pred[cur];
--poz;
}
for(int i = 1; i <= lgmax; ++i)
cout << v[ lg[i] ] << ' ';
return 0;
}