Cod sursa(job #148023)

Utilizator nod_softwareBudisteanu Ionut Alexandru nod_software Data 3 martie 2008 20:33:10
Problema Operatii Scor 60
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.32 kb
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.