Pagini recente » Cod sursa (job #2102717) | Cod sursa (job #2338372) | Cod sursa (job #2822930) | Cod sursa (job #1287320) | Cod sursa (job #115327)
Cod sursa(job #115327)
program operatii;
type vector=array[1..1000]of longint;
var a,b,c:vector;
i,j,min,x,n,poz:integer;
f,g:text;
egal:boolean;
begin
assign(f,'operatii.in');
reset(f);
assign(g,'opreatii.out');
rewrite(g);
readln(f,n);
for i:=1 to n do read(f,a[i]);
x:=0; c:=a;
for i:=1 to n do b[i]:=0;
egal:=true;
repeat
for i:=1 to n do
if c[i]<>b[i] then egal:=false
else egal:=true;
if egal=false then
begin
i:=1;
repeat
while a[i]=0 do i:=i+1;
poz:=i;
min:=a[i];
if (a[i]<>0) then
begin
while (a[i]<>0) do begin
if a[i]<min then min:=a[i];
i:=i+1;
end;
for j:=poz to i-1 do begin
b[j]:=b[j]+min;
a[j]:=a[j]-min;
end;
x:=x+1;
end;
until i>=n-1;
end;
until egal;
write(g,x);
close(f);
close(g);
end.