Pagini recente » Cod sursa (job #2707762) | Cod sursa (job #2645510) | Cod sursa (job #438597) | Cod sursa (job #1236586) | Cod sursa (job #2889389)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define double long double
#define endl '\n'
#define sz size
#define pb push_back
#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
int const INF = LONG_LONG_MAX;
int n;
map<int, int> pr;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
void print(int x)
{
if(pr[x]!=0) print(pr[x]);
fout<<x<<' ';
}
void solve()
{
fin>>n;
vector<int> dp;
for(int i=1;i<=n;i++)
{
int x;
fin>>x;
auto it=lower_bound(all(dp), x);
if(it==dp.end())
{
if(!dp.empty()){pr[x]=(*(it-1));}
else{pr[x]=0;}
dp.pb(x);
}
else
{
if(dp.sz()==1){pr[x]=0;}
else{pr[x]=(*(it-1));}
(*it)=x;
}
}
fout<<dp.sz()<<endl;
int val=*(dp.end()-1);
print(val);
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int tc=1;
//cin>>tc;
while(tc--)
{
solve();
}
return 0;
}