#P10094. Rectangle Partitioning

    ID: 12078 Type: Default 1000ms 256MiB

Rectangle Partitioning

Rectangle Partitioning

You are given a rectangle composed of unit squares with dimensions a×b. You need to make exactly k full cuts (vertical or horizontal) along the grid lines such that the rectangle is partitioned into exactly m smaller rectangles. A full cut means that you cut from one side of the rectangle to the opposite side along a grid line (i.e. you cannot stop midway). The resulting small rectangles do not have to be of equal size.

Note: When you perform a horizontal cut, you are effectively splitting a rectangle into two parts; similarly, when you perform a vertical cut, you are splitting it into two parts. However, if you perform h horizontal cuts and v vertical cuts (with h+v=k), then the total number of small rectangles produced is:

\((h+1)\times(v+1)\)

Your task is to determine whether it is possible to partition the given rectangle using exactly k cuts so that the number of resulting rectangles is exactly m. Remember that you cannot perform more than \(a-1\) horizontal cuts or \(b-1\) vertical cuts because the cuts must be along the grid lines of the a×b rectangle.

inputFormat

The input consists of a single line containing four space-separated integers: a, b, k, and m, where a and b represent the dimensions of the rectangle, k is the number of cuts, and m is the desired number of small rectangles.

outputFormat

Output YES if it is possible to partition the rectangle with exactly k cuts to obtain exactly m small rectangles; otherwise, output NO.

sample

3 3 2 4
YES