fork download
  1. program ask(input, output);
  2.  
  3. const max=100000;
  4.  
  5. var n, i, j, k, count, c:integer;
  6. a: array [1..max] of integer;
  7. fl, flag: boolean;
  8.  
  9. begin
  10. readln(n);
  11. read(a[1]);
  12. count:=0;
  13. i:=2;
  14. while i<=n do
  15. begin
  16. read(a[i]);
  17. if (a[i-1]>0) and (a[i]<0) then
  18. begin
  19. c:=a[i-1];
  20. a[i-1]:=a[i];
  21. a[i]:=c;
  22. count:=count+1;
  23. end;
  24. i:=i+1;
  25. end;
  26.  
  27. flag:=false;
  28. j:=0;
  29. k:=0;
  30. while not flag do
  31. begin
  32. while a[n-j]>0 do j:=j+1;
  33. while a[k+1]<0 do k:=k+1;
  34. i:=k+2;
  35. while i<=n-j do
  36. begin
  37. if (a[i-1]>0) and (a[i]<0) then
  38. begin
  39. c:=a[i-1];
  40. a[i-1]:=a[i];
  41. a[i]:=c;
  42. count:=count+1;
  43. end;
  44. i:=i+1;
  45. end;
  46.  
  47. fl:=true;
  48. i:=k+2;
  49. while fl and (i<=n-j) do
  50. begin
  51. if (a[i-1]>0) and (a[i]<0) then
  52. begin
  53. c:=a[i-1];
  54. a[i-1]:=a[i];
  55. a[i]:=c;
  56. count:=count+1;
  57. fl:=false;
  58. end;
  59. i:=i+1;
  60. end;
  61. if fl=true then flag:=true;
  62. end;
  63.  
  64. writeln(count);
  65. writeln(a[1]);
  66. writeln(a[n]);
  67. end.
Runtime error #stdin #stdout 0.01s 4504KB
stdin
Standard input is empty
stdout
Standard output is empty