Pagini recente » Cod sursa (job #1830692) | Cod sursa (job #1809628) | Cod sursa (job #2185096) | Cod sursa (job #2954800) | Cod sursa (job #1428039)
#include <fstream>
#include <algorithm>
#include <math.h>
using namespace std;
int initial[100005],best[100005],poz[100005];
int main()
{
int sizeI,i,j,cresc,p,pmax,caut;
ifstream f("scmax.in");
ofstream g("scmax.out");
f>>sizeI;
for(i=1;i<=sizeI;i++){
f>>initial[i];
}
p = 0;
pmax = 0;
for(i=1;i<=sizeI;i++){
best[i] = 1;
for(j=i-1;j>=1;j--){
if(initial[j]<initial[i]){
best[i] = max(best[i], best[j]+1);
}
}
if(best[i] > pmax){
pmax = best[i];
p = i;
}
}
poz[pmax] = initial[p];
caut = p;
j = pmax-1;
for(i=p-1;i>0&&j>0;i--){
if(initial[i]<poz[j+1]&&best[i]==(best[caut]-1)){
poz[j] = initial[i];
caut = i;
j--;
}
}
g<<pmax<<'\n';
for(i=1;i<=pmax;i++){
g<<poz[i]<<" ";
}
return 0;
}