Pagini recente » Cod sursa (job #2531085) | Cod sursa (job #988613) | Cod sursa (job #988978) | Cod sursa (job #611771) | Cod sursa (job #2781599)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
#define pip pair<int,pair<int,int>>
set<pip>s;
int pre[100001],v[100001];
int main()
{
int n,i,x;
fin>>n;
for(i=1; i<=n; i++)
{
fin>>v[i];
if(!s.size())
{
s.insert({-v[i],{1,1}});
}
else
{
pip p=*s.begin();
if(p.first>=v[i])
{
s.insert({-v[i],{1,i}});
}
else
{
auto p=*s.lower_bound({-v[i]-1,{2e9+1,2e9+1}});
pip p2;
p2.first=-v[i];
p2.second.first=p.second.first+1;
p2.second.second=i;
pre[i]=p.second.second;
s.insert(p2);
}
}
}
int maxi=0,poz;
for(auto q:s)
{
if(maxi<q.second.first)
{
maxi=q.second.first;
poz=q.second.second;
}
}
fout<<maxi<<"\n";
stack<int>st;
while(poz!=0)
{
st.push(poz);
poz=pre[poz];
}
while(!st.empty())
{
fout<<v[st.top()]<<" ";
st.pop();
}
}