fork download
  1. program events;
  2. Uses Math;
  3. const MAXN =100000;
  4. MAXT =1000000;
  5. type elenco= array[1..MAXN] of Int64;
  6. var N, i, evento:Longint;
  7. X, Y : elenco;
  8. Entrate, Uscite : array [1..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. ultimauscita := Y[N];
  49. numeropresenti:=0; risposta:=0;
  50. for i:=1 to N do begin Entrate[i]:=0; Uscite[i]:=0; end;
  51. for i:= 1 to N do
  52. begin
  53. if X[i]=1 then Entrate[Y[I]] :=1
  54. else if X[i]=-1 then Uscite[Y[I]] :=-1;
  55. end;
  56. for i:= 0 to ultimauscita do
  57. begin
  58. numeropresenti:=numeropresenti+Entrate[i]+Uscite[i];
  59. risposta:=max(risposta, numeropresenti);
  60. end;
  61. writeln (risposta);
  62. end.
Success #stdin #stdout 0.01s 5272KB
stdin
4
1 3
-1 2
1 2
-1 5
stdout
1