Pagini recente » Cod sursa (job #2205522) | Cod sursa (job #2359756) | Cod sursa (job #2944492) | Cod sursa (job #2319351) | Cod sursa (job #3004720)
#include <fstream>
#include <cmath>
#include <queue>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n,v[100001],len[100001],ant[100001],lmax,pmax;
priority_queue<pair<int,int>> q;
int main()
{
fin >> n;
for(int i=1;i<=n;i++)
fin >> v[i];
for(int i=n;i>=1;i--)
{
len[i]=1;
ant[i]=-1;
if(!q.empty())
{
priority_queue<pair<int,int>> q2;
q2=q;
while(v[i]>=v[q2.top().second] && !q2.empty())
q2.pop();
len[i]=1+q2.top().first;
ant[i]=q2.top().second;
}
q.push(make_pair(len[i],i));
if(len[i]>lmax)
{
lmax=len[i];
pmax=i;
}
}
fout << lmax << "\n";
while(pmax!=-1)
{
fout << v[pmax] << " ";
pmax=ant[pmax];
}
return 0;
}