Cod sursa(job #175874)

Utilizator borsosborsos adrian borsos Data 10 aprilie 2008 16:03:17
Problema Subsir crescator maximal Scor 20
Compilator fpc Status done
Runda Arhiva educationala Marime 1.68 kb
var f,g:text;
    a:array[0..100001] of longint;
    n,max,dub,i,start,fin,s,sf:longint;
begin
assign(f,'scmax.in'); reset(f);
assign(g,'scmax.out'); rewrite(g);

readln(f,n);
a[0]:=maxlongint;
max:=1;
start:=1; sf:=1;
dub:=0;
read(f,a[1]);
for i := 2 to n do begin
         read(f,a[i]);
         if a[i-1]<a[i] then begin
                             inc(sf);
                             end;
                             {else}
         if a[i-1]=a[i] then begin
                             inc(sf);
                             inc(dub);
                             end;
                             {else}
         if a[i-1]>a[i] then begin
                             if max <= (sf-start+1)-dub then begin
                                           max:=sf-start+1 - dub;
                                           s:=start;
                                           fin:=sf;

                                                             end;
                             start:=i; sf:=i; dub:=0;
                             end;
         if n=i then begin
                 if max <= (sf-start+1)-dub then begin
                             max:=sf-start+1 - dub;
                             s:=start;
                             fin:=sf;
                             dub:=0;
                                                 end;
                     end;
                    end;

writeln(g,max);
for i := s to fin do begin
           if (i<>s) then begin
               if a[i]<>a[i-1] then write(g,a[i],' ');
                          end else
                                    write(g,a[i],' ');
                     end;
close(f);
close(g);
end.