Pagini recente » Cod sursa (job #2459153) | Cod sursa (job #242474) | Cod sursa (job #1904346) | Cod sursa (job #884882) | Cod sursa (job #3229402)
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <array>
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pll;
#define fast ios:sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll prv[100001],v[100001];
int main()
{
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
ll n, l = 0;
cin>>n;
vector<pll> opt(1, {-1e15,0});
cin>>v[1];
ll x;
opt.push_back({v[1],1});
//if(a.first!=b.first)return a.first<b.first;
//return a.second<b.second;
for(ll i = 2; i <= n; i++)
{
cin>>x;
v[i]=x;
if(x >= opt.back().first)
{
if(x>opt.back().first)prv[i]=opt.back().second,opt.push_back({x,i});
continue;
}
auto poz = lower_bound(opt.begin(), opt.end(), pll(x,0));
//cerr<<i<<' '<<poz->second<<' '<<(poz-1)->second<<'\n';
prv[i]=(poz-1)->second;
(*poz) = {x,i};
}
cout<<opt.size() - 1<<'\n';
x=opt.back().second;
vector<ll>rez;
while(x!=0){
rez.pb(v[x]);
x=prv[x];
}
reverse(all(rez));
for(ll x:rez)cout<<x<<' ';
return 0;
}