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