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 : elenco;
  7. numeropresenti, risposta : 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;
  47. i:=1;
  48. while i<= N do
  49. begin
  50. if Y[i]=Y[i+1] then
  51. begin
  52. if ((X[i]=1) and (X[i+1]=-1)) or ((X[i]=-1) and (X[i+1]=1)) then begin numeropresenti:=numeropresenti; i:=i+2; end
  53. end
  54. else
  55. begin
  56. if X[i]=1 then numeropresenti:=numeropresenti +1
  57. else numeropresenti:=numeropresenti -1;
  58. i:=i+1;
  59. end;
  60. risposta:=max(risposta, numeropresenti) ;
  61.  
  62. end;
  63. writeln (risposta);
  64. end.
Success #stdin #stdout 0s 5296KB
stdin
4
1 3
1 2
-1 4
-1 5
stdout
2