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. Entrate, Uscite : array[0..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; Y[0]:=-1;
  48. for i:=0 to N do begin Entrate[i]:=0; Uscite[i]:=0; end;
  49. writeln(X[3]);
  50. for i:=1 to N do
  51. begin
  52. if Y[i]=Y[i-1] then
  53. begin
  54. if X[i]=1 then Entrate[i-1] :=Entrate[i-1]+1
  55. else if X[i]=-1 then Uscite[i-1] :=Uscite[i-1]-1;
  56. end
  57. else
  58. begin
  59. if X[i]=1 then Entrate[i] :=Entrate[i]+1
  60. else if X[i]=-1 then Uscite[i] :=Uscite[i]-1;
  61. end;
  62. end;
  63. for i:=0 to N do write(entrate[i],' ');writeln;
  64. for i:=0 to N do write(uscite[i],' ');writeln;
  65. for i:= 0 to N do
  66. begin
  67. numeropresenti:=numeropresenti+Entrate[i]+Uscite[i];
  68. writeln(numeropresenti);
  69. risposta:=max(risposta, numeropresenti);
  70. end;
  71. writeln (risposta);
  72. end.
Success #stdin #stdout 0s 5320KB
stdin
6
-1 0
1 0
1 0
1 7
-1 7
-1 10
stdout
-1
0 2 0 0 1 0 0 
0 0 -1 0 -1 0 -1 
0
2
1
1
1
1
0
2