Pagini recente » Cod sursa (job #2320297) | Cod sursa (job #1406300) | Cod sursa (job #3136801) | Cod sursa (job #1002522) | Cod sursa (job #1320086)
#include <fstream>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int lungime,numere[100001],sir[100001],drum[100001],rez1=0,poz,rez2[100001],rezpoz=1;
int main()
{
int i,j,Max=0;;
in>>lungime;
for(i=1; i<=lungime; i++)
{
in>>numere[i];
}
for(i=1; i<=lungime; i++)
{
Max=0;
for(j=i-1; j>=1; j--)
{
if(numere[j]<numere[i]&&sir[j]>Max)
{
Max=sir[j];
drum[i]=j;
}
}
sir[i]=Max+1;
}
for(i=1; i<=lungime; i++)
{
if(i[sir]>rez1)
{
rez1=sir[i];
poz=i;
}
}
out<<rez1<<endl;
while(poz){
rez2[rezpoz]=numere[poz];
poz=drum[poz];
rezpoz++;
}
for(i=rezpoz-1;i>=1;i--){
out<<rez2[i]<<" ";
}
}