Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. program B;
  2. var
  3. N,K,i,j,max:longint;
  4. a:array[1..200000,1..2] of longint;
  5. begin
  6. max:=-2147483647;
  7. readln(N,K);
  8. for i:=1 to N do
  9. begin
  10. readln(a[i,1],a[i,2]);
  11. end;
  12. for i:=1 to N do
  13. for j:=1 to 2 do
  14. if (a[i,j] > max) then max:=a[i,j];
  15. while (K>0) do
  16. begin
  17. for i:=1 to N do
  18. for j:=1 to 2 do
  19. begin
  20. if (a[i,1] = max) and (i<>1) and (i<>N) and (a[i-1,1] > a[i+1,1]) and (a[i-1,1] > a[i,2]) then
  21. begin
  22. a[i-1,1]:=1;
  23. a[i,1]:=1;
  24. max:=-2147483647;
  25. end
  26. else if (a[i,1] = max) and (i<>1) and (i<>N) and (a[i+1,1] > a[i-1,1]) and (a[i+1,1] > a[i,2]) then
  27. begin
  28. a[i+1,1]:=1;
  29. a[i,1]:=1;
  30. max:=-2147483647;
  31. end
  32. else if (a[i,1] = max) and (i<>1) and (i<>N) and (a[i,2] > a[i-1,1]) and (a[i+1,1] < a[i,2]) then
  33. begin
  34. a[i,2]:=1;
  35. a[i,1]:=1;
  36. max:=-2147483647;
  37. end
  38. else if(a[i,2] = max) and (i<>1) and (i<>N) and (a[i-1,2] > a[i+1,2]) and (a[i-1,2] > a[i,1]) then
  39. begin
  40. a[i-1,2]:=1;
  41. a[i,2]:=1;
  42. max:=-2147483647;
  43. end
  44. else if (a[i,2] = max) and (i<>1) and (i<>N) and (a[i+1,2] > a[i-1,2]) and (a[i+1,2] > a[i,1]) then
  45. begin
  46. a[i+1,2]:=1;
  47. a[i,2]:=1;
  48. max:=-2147483647;
  49. end
  50. else if (a[i,2] = max) and (i<>1) and (i<>N) and (a[i,1] > a[i-1,2]) and (a[i+1,2] < a[i,1]) then
  51. begin
  52. a[i,1]:=1;
  53. a[i,2]:=1;
  54. max:=-2147483647;
  55. end
  56. end;
  57. k:=k-1;
  58. end;
  59. for i:=1 to N do
  60. for j:=1 to 2 do
  61. writeln(a[i,j]);
  62. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement