Tin học trẻ A - Vòng Khu vực miền Trung 2022



Comments


  • 3
    nguyendepzai2k9    2:58 p.m. 10 oct, 2024

    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)]

    Processing and getting the final heights

    final_heights = build_wall(N, K, stages)

    Outputting the result

    print(" ".join(map(str, final_heights)))


    • -34
      hdhieu13dana    1:35 p.m. 21 aug, 2024

      This comment is hidden due to too much negative feedback. Click here to view it.