Pagini recente » Cod sursa (job #2390025) | Cod sursa (job #3124563) | Cod sursa (job #827133) | Cod sursa (job #78265) | Cod sursa (job #268798)
Cod sursa(job #268798)
type elemnt = record
val : longint;
nrel : longint;
besti : longint;
end;
var fin,fout : text;
el,ultimu,maxim : elemnt;
N,i,j : longint;
procedure max(a,b : longint);
begin
if a > b then begin
el.besti := a;
el.nrel := ultimu.nrel +1;
end
else begin
el.besti := b;
el.nrel := 1;
end;
end;
begin
assign(fin,'ssm.in');
reset(fin);
assign(fout,'ssm.out');
rewrite(fout);
read(fin,N);
for i := 1 to n do begin
read(fin,el.val);
if i=1 then begin
el.besti := el.val;
el.nrel := 1;
maxim := el;
j := i;
end
else begin
max(ultimu.besti + el.val,el.val);
if maxim.besti < el.besti then begin
maxim := el;
j := i;
end;
ultimu := el;
end;
end;
close(fin);
write(fout,maxim.besti,' ',j - maxim.nrel +1,' ',j);
close(fout);
end.