Pagini recente » Cod sursa (job #1911702) | Cod sursa (job #1235118) | Cod sursa (job #1141029) | Cod sursa (job #1064982) | Cod sursa (job #1155375)
#include <fstream>
#define dim 100001
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int Y,a[dim],poz[dim],best[dim],BEST=-100000,i,j,n,c=1;
int main(){
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
best[n]=1,poz[n]=n;
for(i=n-1;i>=1;i--){
for(j=n;j>i;j--){
if(a[j]>a[i] && best[i]<best[j]+1){
poz[i]=j;
best[i]=best[j]+1;
}
if(!best[i]) best[i]=1,poz[i]=i;
// g<<best[i]<<" ";
if(best[i]>BEST) BEST=best[i],Y=i;
}
}
g<<BEST<<"\n";
while(poz[Y]!=Y){
g<<a[Y]<<" ";
Y=poz[Y];
}
g<<a[Y];
}