#P6953. Box Net Construction

    ID: 20160 Type: Default 1000ms 256MiB

Box Net Construction

Box Net Construction

Bella works at a factory that produces boxes in the shape of a rectangular parallelepiped. A net of a given box is cut from a flat rectangular piece of cardboard of size \(w \times h\). The net is a polygon whose sides are parallel to the sides of the cardboard. When the net is folded along its edges (which are exactly the edges of the box) and the corresponding faces are joined, a box of size \(a \times b \times c\) is formed.

Your task is to write a program that, given \(w, h, a, b, c\), checks whether it is possible to cut a valid net for a box of dimensions \(a \times b \times c\) from a cardboard of size \(w \times h\). You may rotate the net arbitrarily (by a multiple of \(90^\circ\)) when placing it on the cardboard. Note that the net must be contiguous and its edges must align with those of the cardboard.

It turns out that a necessary and sufficient condition is that at least one of the following three candidate arrangements fits into the cardboard (possibly after a \(90^\circ\) rotation):

  • Candidate 1: \(2a+2b+c \le w \) and \(a+b+2c \le h\) (or with \(w\) and \(h\) swapped).
  • Candidate 2: \(2a+b+2c \le w \) and \(a+2b+c \le h\) (or with \(w\) and \(h\) swapped).
  • Candidate 3: \(a+2b+2c \le w \) and \(2a+b+c \le h\) (or with \(w\) and \(h\) swapped).

If at least one of these conditions holds, then it is possible to form the box; otherwise, it is not.

inputFormat

The input consists of a single line with five positive integers \(w, h, a, b, c\) separated by spaces. \(w\) and \(h\) are the dimensions of the cardboard, while \(a, b, c\) are the dimensions of the box.

outputFormat

Output a single line containing either YES if it is possible to create the net for a box of size \(a \times b \times c\) from a cardboard of size \(w \times h\), or NO otherwise.

sample

5 4 1 1 1
YES

</p>