#C11757. Garden Planting
Garden Planting
Garden Planting
In this problem, you are given the dimensions of a garden and several plant species, each requiring a rectangular patch of land. The garden is represented as a grid of size (G_{width} \times G_{height}). Each species is represented by its required rectangular dimensions (width and height). Your task is to determine whether it is possible to plant all species in the garden such that none of them overlap and none exceed the boundaries of the garden.
The species must be placed in a non-overlapping manner. The placement strategy is not prescribed, so any valid configuration that fits the species is acceptable.
For example, if the garden is 10 by 10 and there are three species with dimensions (3, 3), (4, 4), and (4, 2) respectively, then the answer is YES if all species can be arranged in the garden without overlapping.
If a species does not fit anywhere in the remaining free space, the answer is NO.
inputFormat
The input is read from standard input and has the following format:
The first line contains three integers: (g_{width}), (g_{height}) and (m), where (g_{width}) and (g_{height}) denote the width and height of the garden respectively, and (m) is the number of species.
This is followed by (m) lines, each containing two integers (w) and (h) representing the width and height required for a species.
outputFormat
Print a single line to standard output: "YES" if all the species can be planted without overlapping or exceeding the garden boundaries, otherwise "NO".## sample
10 10 3
3 3
4 4
4 2
YES