#K40482. Enclosure Arrangement for Animal Groups
Enclosure Arrangement for Animal Groups
Enclosure Arrangement for Animal Groups
You are given an enclosure of dimensions \( H \times W \) and \( n \) groups of animals. Each group \( i \) requires a rectangular area of size \( h_i \times w_i \). The task is to determine if it is possible to place all animal groups inside the enclosure without overlapping. The placement is possible if the sum of the areas of all groups does not exceed the area of the enclosure.
Note: You only need to check if the total required area is less than or equal to the area of the enclosure. There is no need to consider the exact layout or placement.
Input Format: The first line contains three integers \( H \), \( W \) and \( n \). The following \( n \) lines each contain two integers \( h_i \) and \( w_i \) representing the dimensions of the \( i^{th} \) animal group.
Output Format: Output a single line containing "YES" if all groups can be placed, or "NO" otherwise.
Example:
Input: 10 12 3 2 3 4 6 4 6</p>Output: YES
inputFormat
The input begins with a line containing three positive integers \( H \), \( W \), and \( n \), where \( H \) and \( W \) denote the height and width of the enclosure, and \( n \) denotes the number of animal groups. This is followed by \( n \) lines, each containing two integers \( h_i \) and \( w_i \), representing the height and width required by the \( i^{th} \) animal group.
All input is read from standard input (stdin).
outputFormat
Output a single line containing "YES" if the combined area of all animal groups is less than or equal to the area of the enclosure, otherwise output "NO".
All output should be written to standard output (stdout).
## sample10 12 3
2 3
4 6
4 6
YES
</p>