Pagini recente » Cod sursa (job #1587426) | Cod sursa (job #2782738) | Cod sursa (job #369319) | Cod sursa (job #163813) | Cod sursa (job #1152578)
#include <fstream>
using namespace std;
ifstream is ("scmax.in");
ofstream os ("scmax.out");
int n;
int D[100002], V[100002], T[100002], B[100002], lg = 1;
int BS(int x);
void Out(int i);
int main()
{
is >> n;
for (int i = 1; i <= n; ++i)
is >> V[i];
D[1] = B[1] = 1; B[0] = 0;
int pos;
for (int i = 2; i <= n; ++i)
{
pos = BS(V[i]);
T[i] = B[pos];
D[i] = pos+1;
B[pos+1] = i;
if (lg < pos+1) lg = pos+1;
}
os << lg << '\n';
pos = B[lg];
Out(pos);
is.close();
os.close();
return 0;
}
int BS(int x)
{
int L = 0, R = lg, M;
while (L <= R)
{
M = (L+R)/2;
if (V[B[M]] < x && V[B[M+1]] >= x) return M;
else if (V[B[M]] < x) L = M+1;
else R = M-1;
}
return lg;
};
void Out(int i)
{
if (T[i] > 0) Out(T[i]);
os << V[i] << ' ';
};