#K9841. Art Gallery Arrangement
Art Gallery Arrangement
Art Gallery Arrangement
In this problem, you are given a canvas with a height and width, and a list of rectangular art pieces. Your task is to determine whether it is possible to place all the art pieces on the canvas without overlapping and staying within the boundaries.
The art pieces can be arranged in any order. They must be placed sequentially in rows. In each row, pieces are placed side by side until no more pieces can fit horizontally, and then a new row is started. Formally, given a canvas with width (W) and height (H), an arrangement is valid if when the pieces are partitioned into rows, the sum of the maximum heights of each row does not exceed (H) and the total width of the pieces in each row does not exceed (W).
inputFormat
The input is provided via standard input (stdin).
The first line consists of two integers (n) and (m), representing the canvas height and width respectively.
The second line contains an integer (k), the number of art pieces.
Each of the following (k) lines contains two integers (w_i) and (h_i), which are the width and height of the (i)-th art piece.
outputFormat
Output a single line to standard output (stdout) containing the word YES if it is possible to arrange all art pieces on the canvas without overlapping and within the boundaries, otherwise output NO.## sample
5 5
2
4 2
2 3
YES