Pagini recente » Cod sursa (job #2750183) | Borderou de evaluare (job #1036395) | Cod sursa (job #1845468) | Cod sursa (job #2287201) | Cod sursa (job #175897)
Cod sursa(job #175897)
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:=0;
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;
max:=0;
for i := s to fin do begin
if (i<>s) then begin
if a[i]<>a[i-1] then begin inc(max); a[max]:=a[i] end;
end else
begin inc(max); a[max]:=a[i] end;
end;
writeln(g,max);
for i := 1 to max do write(g,a[i],' ');
close(f);
close(g);
end.