Pagini recente » Cod sursa (job #2696693) | Cod sursa (job #899411) | Cod sursa (job #2309179) | Cod sursa (job #1286160) | Cod sursa (job #147997)
Cod sursa(job #147997)
program operatii2;
{$APPTYPE CONSOLE}
uses
SysUtils;
var c,n,max,i,j:longint;
v:array [1..1000000] of longint;
fin,fout:text;
{*------------------------*}
procedure citire;
begin
assign(fin,'operatii.in'); reset(fin);
assign(fout,'operatii.out'); rewrite(fout);
readln(fin,n);
max:=-1;
for i:=1 to n do
begin
read(fin,v[i]);
if max < v[i] then max:=v[i];
end;
close(fin);
end;
{*------------------------*}
function cauta:integer;
begin
cauta:=0;
for i:=1 to n do
if v[i] = max then
begin
cauta:=i;
exit;
end;
end;
{*----------MAIN----------*}
begin
citire;
inc(max);
c:=0;
while max>1 do
begin
dec(max);
while cauta > 0 do
begin
while v[i]=max do
begin
inc(i);
dec(v[i-1]);
end;
inc(c);
end;
end;
writeln(fout,c);
close(fout);
end.