fork download
  1. program squareunion;
  2. const
  3. MAXN = 100000;
  4. type elenco= Array [1..MAXN] of LongInt;
  5. var
  6. N, i, base, altezza : LongInt;
  7. R, X, Inizio, Fine :elenco;
  8. ans, areaoverl : Int64;
  9.  
  10. Procedure scambia (var a,b: Longint);
  11. var x:Longint;
  12. begin
  13. x:=a;
  14. a:=b;
  15. b:=x;
  16. end;
  17.  
  18. Procedure ordinamento (estremoi,estremos: Longint; var v : elenco; var u:elenco; var w:elenco; ordinato:boolean);
  19. var inf, sup, medio:Longint;
  20. pivot :Longint;
  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. scambia(w[inf],w[sup]);
  37. inf:=inf+1;
  38. sup:=sup-1;
  39. end;
  40. until inf>sup;
  41. if (estremoi<sup) then ordinamento(estremoi,sup,v,u,w,ordinato);
  42. if (inf<estremos) then ordinamento(inf,estremos,v,u,w,ordinato);
  43. end;
  44.  
  45.  
  46.  
  47. begin
  48. {
  49.   uncomment the two following lines if you want to read/write from files
  50.   assign(input, 'input.txt'); reset(input);
  51.   assign(output, 'output.txt'); rewrite(output);
  52. }
  53.  
  54. ReadLn(N);
  55.  
  56. for i:=1 to N do
  57. Read(X[i]);
  58. ReadLn();
  59. ans:=0;
  60. for i:=1 to N do begin Read(R[i]); ans:=ans+sqr(2*R[i]); end;
  61. ReadLn();
  62. areaoverl := 0;
  63. for i:=1 to N do
  64. begin
  65. Inizio[i]:=X[i]-R[i];
  66. Fine[i]:=X[i]+R[i];
  67. end;
  68. ordinamento(1,N,Inizio, Fine, R, true);
  69. For i:=1 to N do write (Inizio[i],' '); writeln;
  70. For i:=1 to N do write (Fine[i],' '); writeln;
  71. For i:=1 to N do write (R[i],' '); writeln;
  72.  
  73. For i:=1 to N-1 do
  74. begin
  75. if Fine[i]<=Inizio[i+1] then areaoverl:=0
  76. else
  77. begin
  78. if Fine[i]>Fine[i+1] then areaoverl:=sqr(2*R[i+1])
  79. else
  80. begin
  81. base:=Fine[i]-Inizio[i+1];
  82. if R[i]<=R[i+1] then altezza:=2*R[i]
  83. else altezza:=2*R[i+1];
  84. areaoverl:=base*altezza;
  85.  
  86. end;
  87. end;
  88. writeln(areaoverl);
  89. ans:= ans-areaoverl;
  90. end;
  91. WriteLn(ans);
  92.  
  93. end.
  94.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout


0