Cod sursa(job #175863)

Utilizator borsosborsos adrian borsos Data 10 aprilie 2008 15:50:19
Problema Subsir crescator maximal Scor 20
Compilator fpc Status done
Runda Arhiva educationala Marime 2.12 kb
var f,g:text;
    a:array[0..100000] 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);
                             if n=i then begin
                                 if max < (sf-start+1)-dub then begin
                                           max:=sf-start+1 - dub;
                                           s:=start;
                                           fin:=sf;
                                                             end;
                                              end;
                             end
                             else
         if a[i-1]=a[i] then begin
                             inc(sf);
                             inc(dub);
                             if n=i then begin
                                 if max < (sf-start+1)-dub then begin
                                           max:=sf-start+1 - dub;
                                           s:=start;
                                           fin:=sf;
                                                             end;
                                         end;
                             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;

                    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.