Pagini recente » Cod sursa (job #2551742) | Cod sursa (job #2934785) | Cod sursa (job #2140834) | Cod sursa (job #31202) | Cod sursa (job #148023)
Cod sursa(job #148023)
program operatii2;
{$APPTYPE CONSOLE}
uses
SysUtils;
var t,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);
i:=0;
while i < n do
begin
inc(i);
t:=0;
while v[i]=max do
begin
dec(v[i]);
inc(c);
inc(i);
inc(t);
end;
if t>0 then c:=c-t+1;
end;
end;
writeln(fout,c);
close(fout);
end.