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