def build_wall(N, K, stages):
heights = [0] * N # Initialize all columns to height 0
for stage in stages:
Op, Left, Right, Height = stage
if Op == 1: # Adding bricks
for i in range(Left, Right + 1):
if heights[i] < Height:
heights[i] = Height
elif Op == 2: # Removing bricks
for i in range(Left, Right + 1):
if heights[i] > Height:
heights[i] = Height
return heights
Reading input
N, K = map(int, input().split())
stages = [list(map(int, input().split())) for _ in range(K)]
Comments
def build_wall(N, K, stages):
heights = [0] * N # Initialize all columns to height 0
Reading input
N, K = map(int, input().split())
stages = [list(map(int, input().split())) for _ in range(K)]
Processing and getting the final heights
final_heights = build_wall(N, K, stages)
Outputting the result
print(" ".join(map(str, final_heights)))
This comment is hidden due to too much negative feedback. Click here to view it.