Pagini recente » Cod sursa (job #1391930) | Cod sursa (job #1239527) | Cod sursa (job #1391929) | Cod sursa (job #1320700) | Cod sursa (job #3346275)
#include <bits/stdc++.h>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int a[100005], v[100005];
int main()
{
int n;
f >> n;
for(int i=1; i<=n; i++)
f >> a[i];
int nrmax=0;
bool pus=false;
for(int i=n; i>=1; i--)
{
pus=false;
for(int j=i+1; j<=n; j++)
{
if(a[j]>a[i])
{
pus=true;
v[i]=v[j]+1;
break;
}
}
if(pus==false)
v[i]=1;
if(v[i]>nrmax)
nrmax=v[i];
}
g << nrmax << '\n';
for(int i=1; i<=n; i++)
{
if(v[i]==nrmax)
g << a[i] << " ", nrmax--;
}
return 0;
}