Cod sursa(job #147994)

Utilizator nod_softwareBudisteanu Ionut Alexandru nod_software Data 3 martie 2008 19:51:58
Problema Operatii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.06 kb
program operatii;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var a,b,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
     max:=0;
     cauta:=0;
     for i:=a to b do
         if v[i] > max then
         begin
              max:=v[i];
         end;
     cauta:=max;         
end;   
{*----------MAIN----------*}  
begin  
     citire;   
     //inc(max);
     c:=0;
     j:=0;
     while j<n do
     begin
        inc(j);
        a:=j;
        while ((v[j]<>0) and (j < n)) do inc(j);
        b:=j;
        c:=c+cauta;
     end;   
     writeln(fout,c);   
     close(fout);   
end.