Cod sursa(job #1344310)

Utilizator laura.calimanLaura Caliman laura.caliman Data 16 februarie 2015 16:52:41
Problema Subsir crescator maximal Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.73 kb
var n,i,j,k:longint;
    a,b:array[0..100000] of longint;
    
procedure bin(s:string);
var i:longint; r:boolean;
begin
  if length(s)=n then begin
    r:=true;
    for i:=1 to n-1 do 
      if s[i]='0' then 
        if a[i]>=a[i+1] then r:=false;
    if r and (k>j) then begin
      j:=0;
      for i:=1 to n do 
        if s[i]='0' then begin
          inc(j);
          b[j]:=a[i];
        end;
    end;
  end else begin
    inc(k);
    bin(s+'0');
    dec(k);
    bin(s+'1');
  end;
end;
    
begin
  assign(input,'scmax.in');
  assign(output,'scmax.out');
  reset(input);
  rewrite(output);
  read(n);
  for i:=1 to n do read(a[i]);
  j:=0;
  bin('');
  writeln(j);
  for i:=1 to j do write(b[i],' ');
end.