Pagini recente » Cod sursa (job #2446011) | Cod sursa (job #706641) | Cod sursa (job #19754) | Cod sursa (job #143903) | Cod sursa (job #3169462)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
const int NMAX=1e5+1;
const int INF=0x3f3f3f;
int n,lmax;
int v[NMAX], d[NMAX], tata[NMAX], S[NMAX];
void citire() {
f >> n;
for (int i=1;i<=n;i++) {
f >> v[i];
d[i]=INF;
}
}
void solve() {
for (int i=1;i<=n;i++) {
int st=1,dr=lmax,m=0,poz=0;
while (st<=dr) {
m=(st+dr)/2;
if (v[i] > v[d[m]]) {
st=m+1;
poz=m;
} else {
dr=m-1;
}
}
if (poz==lmax) {
lmax++;
d[lmax]=i;
tata[i]=d[poz];
} else {
d[poz+1]=i;
tata[i]=d[poz];
}
}
}
void afis(int i) {
if (i>0) {
afis(tata[i]);
g << v[i] << ' ';
}
}
int main()
{
citire();
solve();
g << lmax << '\n';
afis(d[lmax]);
return 0;
}