Pagini recente » Cod sursa (job #1457377) | Cod sursa (job #1089109) | Cod sursa (job #2562555) | Cod sursa (job #1426802) | Cod sursa (job #2636321)
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int lungime[100005], v[100005], lgmax, n,pre[100005];
void citire() {
fin >> n;
for(int i = 1; i <= n; i ++)
fin >> v[i];
}
void solve() {
for(int i = 1; i <= n; i++) {
int st = 1, dr = lgmax, found = 0;
if(v[i] > v[lungime[lgmax]]) found = lgmax +1;
while(st <= dr) {
int m =(st+dr)/2;
if(v[lungime[m]] >= v[i] && v[lungime[m-1]] < v[i]) {
found = m;
break;
} else if(v[lungime[m]] >= v[i])
dr = m-1;
else st=m+1;
}
lungime[found] = i;
lgmax = max(lgmax, found);
pre[i] = lungime[found-1];
}
fout << lgmax << '\n';
}
void afis(int x) {
if(x) {
afis(pre[x]);
fout << v[x] << ' ';
}
}
int main() {
citire();
solve();
afis(lungime[lgmax]);
}