Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

armadi

program armadi(input,output);

var N, K:longint; 
const nMax=100001;
var D: array [1..nMax] of longint;
var i,j, aux, max,n_m, DISTANZA, INDMAX: longint;
var DD: array [1..nMax] of longint;
var m: array [1..nMax] of longint;


begin
assign(input, 'input.txt'); reset(input);
assign(output, 'output.txt'); rewrite(output);



read (N); read( k);

 for i:=1 to n do  
    begin
         read(D[i]);
    end;

D[n+1]:=k;



for j := 1 to (N-1) do
  for i := (j+1) to n do
    if D[j] > D[i] then begin
      {scambio valori};
      aux := D[j];
      D[j] := D[i];
      D[i] := aux
    end;

DD[1]:=D[1]-D[0];
DD[N+1]:=K-D[N];
for i:=2 to N do
begin
 DD[i]:=round((D[i]-D[i-1])/2);
end;



max:=DD[1];
n_m:=1;
m[n_m]:=1;

FOR i:=2 TO n+1 DO BEGIN
IF DD[i] > max THEN BEGIN
max:=DD[i];
n_m:=0;
n_m:=n_m+1;
m[n_m]:=i
END ELSE
IF DD[i] = max THEN BEGIN
n_m:=n_m+1;
m[n_m]:=i
END
END;
FOR i:=1 TO n_m DO
BEGIN
INDMAX:=m[I];
END;

CASE INDMAX OF
    1: DISTANZA:=0;
    ELSE DISTANZA:=D[INDMAX-1]+DD[INDMAX];
    
END;


WRITELN(distanza);

end.

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.