Pagini recente » Cod sursa (job #2570276) | Cod sursa (job #1712300) | Cod sursa (job #1372981) | Cod sursa (job #626552) | Cod sursa (job #174274)
Cod sursa(job #174274)
Program operatii;
type vec=array[1..100000] of longint;
var v: vec;
n: longint;
Procedure prelucrare;
var i,nr: longint;
gata: boolean;
t: text;
begin
nr:=0;
repeat
gata:=true;
i:=1;
repeat
if v[i]<>0 then
begin
gata:=false;
v[i]:=v[i]-1;
nr:=nr+1;
repeat
i:=i+1;
if v[i]<>0 then v[i]:=v[i]-1;
until v[i+1]=0;
end;
i:=i+1;
until i>=n;
until gata;
assign(t,'operatii.out'); rewrite(t);
write(t,nr);
close(t);
end;
Procedure cit_fis;
var t: text;
i: longint;
begin
assign(t,'operatii.in'); reset(t);
readln(t,n);
for i:=1 to n do
read(t,v[i]);
close(t);
prelucrare;
end;
begin
cit_fis;
end.