Advertisement
savrasov

Untitled

Jan 30th, 2017
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. var
  2. n, i: integer;
  3. b, a: array [-100000..100000] of integer;
  4.  
  5. procedure push(a, v: integer);
  6. begin
  7. if (b[v] = 0) then b[v] := a
  8. else
  9. begin
  10. if(a<b[v]) then push(a, v * 2)
  11. else push(a, v * 2 + 1);
  12. end;
  13. end;
  14.  
  15. procedure outp(v: integer);
  16. begin
  17. if(b[v * 2 + 1] <> 0) then
  18. outp(v*2+1);
  19. if(b[v*2] <> 0) then
  20. outp(v*2);
  21. write (b[v]);
  22. if(v <> 1) then
  23. write(' ');
  24. end;
  25.  
  26. begin
  27. readln(n);
  28. for i := -100000 to 100000 do
  29. b[i] := 0;
  30. for i := 1 to n do
  31. read(a[i]);
  32. for i := n downto 1 do
  33. push(a[i], 1);
  34. outp(1);
  35. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement