Pagini recente » Cod sursa (job #438608) | Cod sursa (job #3213500) | Cod sursa (job #1095304) | Cod sursa (job #357909) | Cod sursa (job #2376401)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
const int MAXN = 100000 + 5;
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int n,v[MAXN],last[MAXN],aux[MAXN];
int index = 0;
int cautbinar_up(int x,int maxindex){
int pas = 1<<28, r = 0;
while(pas){
if(r + pas <= maxindex and aux[r + pas] <= x)
r += pas;
pas /= 2;
}
if(!r)
return maxindex;
return r;
}
void afis(){
for(int i = 1; i <= index; i++)
cout<<aux[i]<<" ";
cout<<endl;
}
int main()
{
in>>n;
for(int i = 1; i <= n; i++)
in>>v[i];
for(int i = 1; i <= n; i++){
last[i] = lower_bound(aux + 1,aux + index + 1,v[i]) - aux;
index = max(index,last[i]);
aux[last[i]] = v[i];
}
out<<index<<"\n";
vector<int>ans;
int curent = index;
for(int i = n; i >= 1; i--){
if(last[i] == curent){
ans.push_back(v[i]);
curent--;
}
}
reverse(ans.begin(),ans.end());
for(auto x : ans)
out<<x<<" ";
return 0;
}