numarr, de7

04/02/2023

doan gia khanh sent

Code
program numarr;
uses crt;
const fi='numarr.inp';fo='numarr.out';
var  f : text;
     a : array[1..1000000] of int64;
     n,i : longint;
     min,max : int64;

procedure nhap;
begin
    assign(f, fi); reset(f);
    readln(f,n);
    for i := 1 to n do readln(f, a[i]);
    close(f);
end;

BEGIN
    clrscr;
    nhap;
    min := a[1];
    max := a[1];
    for i:= 1 to n do
     begin
         if (min > a[i]) then min := a[i];
         if (max < a[i]) then max := a[i];
     end;
    assign(f,fo);rewrite(f);
    write(f, max-min);
    close(f);

END.