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. for i:=1 to n do read(a[i]);
  12.  
  13. count:=0;
  14. flag:=false;
  15. j:=0;
  16. k:=0;
  17. while not flag do
  18. begin
  19. while a[n-j]>0 do j:=j+1;
  20. while a[k+1]<0 do k:=k+1;
  21. i:=k+2;
  22. while i<=n-j do
  23. begin
  24. if (a[i-1]>0) and (a[i]<0) then
  25. begin
  26. c:=a[i-1];
  27. a[i-1]:=a[i];
  28. a[i]:=c;
  29. count:=count+1;
  30. end;
  31. i:=i+1;
  32. end;
  33.  
  34. fl:=true;
  35. i:=k+2;
  36. while fl and (i<=n-j) do
  37. begin
  38. if (a[i-1]>0) and (a[i]<0) then
  39. begin
  40. c:=a[i-1];
  41. a[i-1]:=a[i];
  42. a[i]:=c;
  43. count:=count+1;
  44. fl:=false;
  45. end;
  46. i:=i+1;
  47. end;
  48. if fl=true then flag:=true;
  49. end;
  50.  
  51. writeln(count);
  52. writeln(a[1]);
  53. writeln(a[n]);
  54. end.
Runtime error #stdin #stdout 0.01s 4504KB
stdin
Standard input is empty
stdout
Standard output is empty