fork download
  1. program malls;
  2. const MAX=100000;
  3. type elenco = array[0..Max-1] of qword;
  4. var N, i :longint;
  5. D : elenco;
  6. K, maxdist, pos : qword;
  7. diff : array[0..MAX] of qword;
  8.  
  9. procedure scambia (var x,y: qword);
  10. var t:qword;
  11. begin
  12. t:=x;
  13. x:=y;
  14. y:=t;
  15. end;
  16. Procedure ordinamento (estremoi,estremos: qword; var v : elenco; ordinato:boolean);
  17. var inf, sup, medio:qword;
  18. pivot : qword;
  19. begin
  20. inf:=estremoi;
  21. sup:=estremos;
  22. medio:= (estremoi+estremos) div 2;
  23. pivot:=v[medio];
  24. repeat
  25. if (ordinato) then
  26. begin
  27. while (v[inf]<pivot) do inf:=inf+1;
  28. while (v[sup]>pivot) do sup:=sup-1;
  29. end;
  30. if inf<=sup then
  31. begin
  32. scambia(v[inf],v[sup]);
  33. inf:=inf+1;
  34. sup:=sup-1;
  35. end;
  36. until inf>sup;
  37. if (estremoi<sup) then ordinamento(estremoi,sup,v,ordinato);
  38. if (inf<estremos) then ordinamento(inf,estremos,v,ordinato);
  39. end;
  40. begin
  41. readln(N,K);
  42. for i:=0 to N-1 do read(D[i]); readln;
  43. maxdist:=0;
  44. ordinamento (0,N-1,D, true);
  45. for i:=0 to N-1 do write(D[i+1]- D[i],' '); end.
  46. diff[0]:=D[0]; diff[N-1]:=K-D[N-1]; diff[1]:=D[2]-D[1]; writeln(diff[1]);
  47. for i:=1 to N-2 do begin diff[i]:=D[i+1] - D[i]; write(diff[i],' '); end; writeln; end.
  48.  
  49. end.
  50. for i:= 0 to n - 1 do
  51. begin
  52. if (D[i + 1] - D[i]) >= maxdist then
  53. begin
  54. maxdist := D[i + 1] - D[i];
  55. pos := D[i];
  56. end;
  57. if ((D[0] <> 0) and (D[0] >= maxdist/2)) then
  58. begin
  59. maxdist := 0;
  60. pos := 0;
  61. end;
  62. if (k - D[n - 1]) >= max/2 then
  63. if (k - D[n - 1]) >= D[0] then
  64. begin
  65. maxdist := 0;
  66. pos := k;
  67. end;
  68. end;
  69. writeln ((max div 2) + pos);
  70. end.
  71.  
Success #stdin #stdout 0s 5312KB
stdin
5 50
17 4 36 41 44
stdout
13 19 5 3 18446744073709551572