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

stdout
50045