Cod sursa(job #175826)

Utilizator borsosborsos adrian borsos Data 10 aprilie 2008 14:26:37
Problema Subsir crescator maximal Scor 20
Compilator fpc Status done
Runda Arhiva educationala Marime 1.55 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;
for i := 1 to n do begin
         read(f,a[i]);
         if a[i]>a[i-1] then begin
                        inc(sf);
                             end else
         if a[i]=a[i-1] then begin
                        inc(sf);
                        inc(dub);
                             end;
         if (a[i]<a[i-1])or(i=n) then begin
                        if (sf-start+1)-dub>max then begin
                                               s:=start;
                                               fin:=sf;
                                               max:=(sf-start+1)-dub;
                                               start:=i;
                                               sf:=i;
                                               dub:=0;
                                                     end else
                                               begin
                                               start:=i; sf:=i; 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.