Pagini recente » Cod sursa (job #2915019) | Cod sursa (job #2870804) | Cod sursa (job #276820) | Cod sursa (job #885711) | Cod sursa (job #1089815)
using namespace std;
#include<fstream>
#include<iostream>
ifstream f("scmax.in");
ofstream g("scmax.out");
struct specialNr
{
int value, prev, count;
};
int n;
specialNr best[100001];
void write(int p)
{
if(best[p].prev != 0)
write(best[p].prev);
g<<best[p].value<<' ';
}
int main()
{
int i,j;
f>>n;
for(i=1;i<=n;i++)
{
f>>best[i].value;
for(j=1;j<i;j++)
if(best[j].value < best[i].value && best[j].count >= best[i].count)
{
best[i].count = best[j].count+1;
best[i].prev = j;
}
}
int poz,max = -1;
//select max
for(i=1;i<=n;i++)
{
if(max<best[i].count)
{
max = best[i].count;
poz = i;
}
}
g<<max+1<<'\n';
write(poz);
return 0;
}