Pagini recente » Cod sursa (job #3126653) | Cod sursa (job #2570870) | Cod sursa (job #508552) | Cod sursa (job #2959138) | Cod sursa (job #2241005)
#include <fstream>
using namespace std;
int n, i, j, k, maxim=-1, poz;
int v[100001], l[100001], sol[100001];
int main () {
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
fin>>n;
for (i=1;i<=n;i++) {
fin>>v[i];
}
for (i=1;i<=n;i++) {
l[i]=1;
for (j=i-1;j>=1;j--) {
if (v[i]>v[j]) {
if (l[i]<l[j]+1)
l[i]=l[j]+1;
}
if (l[i]>maxim) {
maxim=l[i];
poz=i;
}
}
}
k=maxim;
sol[k]=v[poz]; k--;
for (i=poz-1;i>=1 && k>0; i--) {
if (v[i]<sol[k+1] && l[i]==k) {
sol[k--]=v[i];
}
}
fout<<maxim<<"\n";
for (i=1;i<=maxim;i++)
fout<<sol[i]<<" ";
return 0;
}