fork download
  1. program events;
  2. Uses Math;
  3. const MAXN =100000;
  4. type elenco= array[1..MAXN] of Int64;
  5. var N, i, h:Longint;
  6. X, Y : elenco;
  7. numeropresenti, OraEvento, risposta : int64;
  8. EntrateUscite : array[1..MAXN] of int64;
  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; OraEvento:=-1; h:=0;
  48. for i:=1 to N do EntrateUscite[i]:=0;
  49. for i:=1 to N do
  50. begin
  51. if Y[i]=OraEvento then
  52. begin
  53. if X[i]=1 then EntrateUscite[h] :=EntrateUscite[h]+1
  54. else if X[i]=-1 then EntrateUscite[h] :=EntrateUscite[h]-1;
  55. end
  56. else
  57. begin
  58. h:=h+1;
  59. if X[i]=1 then EntrateUscite[h] :=EntrateUscite[h]+1
  60. else if X[i]=-1 then EntrateUscite[h] :=EntrateUscite[h]-1;
  61. OraEvento:=Y[i];
  62. end;
  63. end;
  64. for i:= 1 to h do
  65. begin
  66. numeropresenti:=numeropresenti+EntrateUscite[i];
  67. risposta:=max(risposta, numeropresenti);
  68. end;
  69. writeln (risposta);
  70. end.
Success #stdin #stdout 0.01s 5316KB
stdin
6
-1 0
1 0    
1 0
1 7
-1 7
-1 10
stdout
1