Pagini recente » Cod sursa (job #1268947) | Cod sursa (job #3270033) | Cod sursa (job #299046) | Cod sursa (job #2143923) | Cod sursa (job #1860939)
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int v[100010], lung[100010], pred[100010], i, indicemax, mx;
int n;
void subsir(int n)
{
if(pred[n]!=0)
subsir(pred[n]);
fout<<v[n]<<' ';
}
int main()
{
std::ios::sync_with_stdio(false);
fin>>n;
fin>>v[++i];
while(fin>>n)
{
v[++i]=n;
mx=0;
for(int j=1;j<i;j++)
{
if(v[j]<v[i])
{
if(lung[j]>mx)
mx=lung[j], pred[i]=j;
}
}
lung[i]=mx;
if(lung[i]>indicemax)
indicemax=lung[i];
}
subsir(indicemax);
return 0;
}