Pagini recente » Cod sursa (job #1354923) | Cod sursa (job #839151) | Cod sursa (job #2945580) | Cod sursa (job #295018) | Cod sursa (job #1706511)
#include <fstream>
using namespace std;
ifstream cin ("scmax.in");
ofstream cout ("scmax.out");
int a[2000000010], d[2000000010], p[2000000010], n, k;
void dinamica (){
int max, max2=n, poz;
d[n]=1;
p[n]=0;
for (int i=n-1; i>=1; i--){
poz=0; max=0;
for (int j=i+1; j<=n; j++)
if (a[i]<a[j] && d[j]>max){
max=d[j];
poz=j;
}
d[i]=1+max;
p[i]=poz;
if (d[i]>d[max2]) max2=i;
}
cout<<d[max2]<<'\n';
while (max2>0){
cout<<a[max2]<<" ";
max2=p[max2];
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
dinamica();
return 0;
}