Pagini recente » Cod sursa (job #3192596) | Cod sursa (job #1348276) | Cod sursa (job #549685) | Cod sursa (job #154688) | Cod sursa (job #2376419)
#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;
}
return r + 1;
}
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] = cautbinar_up(v[i],index);
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;
}