fork download
  1. program events;
  2. Uses Math;
  3. const MAXN =100000;
  4. type elenco= array[1..MAXN] of Int64;
  5. var N, i :Longint;
  6. X, Y, Entrate, Uscite : elenco;
  7. numeropresenti, risposta : int64;
  8.  
  9.  
  10. Procedure scambia (var a,b: Int64);
  11. var x:Int64;
  12. begin
  13. x:=a;
  14. a:=b;
  15. b:=x;
  16. end;
  17. Procedure ordinamento (estremoi,estremos: Int64; var v : elenco; var u : elenco; ordinato:boolean);
  18. var inf, sup, medio:Int64;
  19. pivot :Int64;
  20. begin
  21. inf:=estremoi;
  22. sup:=estremos;
  23. medio:= (estremoi+estremos) div 2;
  24. pivot:=v[medio];
  25. repeat
  26. if (ordinato) then
  27. begin
  28. while (v[inf]<pivot) do inf:=inf+1;
  29. while (v[sup]>pivot) do sup:=sup-1;
  30. end;
  31. if inf<=sup then
  32. begin
  33. scambia(v[inf],v[sup]);
  34. scambia(u[inf],u[sup]);
  35. inf:=inf+1;
  36. sup:=sup-1;
  37. end;
  38. until inf>sup;
  39. if (estremoi<sup) then ordinamento(estremoi,sup,v,u, ordinato);
  40. if (inf<estremos) then ordinamento(inf,estremos,v, u, ordinato);
  41. end;
  42.  
  43. begin
  44. readln(N);
  45. for i:=1 to N do readln(X[i],Y[i]);
  46. ordinamento (1,N,Y,X, true);
  47. numeropresenti:=0; risposta:=0;
  48. for i:=2 to N do begin Entrate[i]:=0; Uscite[i]:=0; end;
  49. Entrate[1]:=1; Uscite[1]:=0;
  50. if Y[1]=Y[2] then if ((X[1]=-1) and (X[2]=1)) then scambia(X[1],X[2]);
  51. for i:=2 to N do
  52. begin
  53. if Y[i]=Y[i-1] then
  54. begin
  55. if X[i]=1 then Entrate[i-1] :=Entrate[i-1]+1
  56. else if X[i]=-1 then Uscite[i-1] :=Uscite[i-1]-1;
  57. end
  58. else
  59. begin
  60. if X[i]=1 then Entrate[i] :=Entrate[i]+1
  61. else if X[i]=-1 then Uscite[i] :=Uscite[i]-1;
  62. end;
  63. end;
  64. for i:= 1 to N do
  65. begin
  66. numeropresenti:=numeropresenti+Entrate[i]+Uscite[i];
  67. risposta:=max(risposta, numeropresenti);
  68. end;
  69. writeln (risposta);
  70. end.
  71.  
Success #stdin #stdout 0.01s 5324KB
stdin
10
1 0
-1 0
1 4
1 5
1 5
-1 5
1 6
-1 7
-1 7
-1 8
stdout
3