#K40442. Frame Placement Problem
Frame Placement Problem
Frame Placement Problem
You are given a wall with dimensions \(W\) (width) and \(H\) (height), and you want to place \(n\) rectangular frames on it. Each frame has dimensions \(w\) (width) and \(h\) (height). The frames cannot overlap. However, you are allowed to rotate the frames by \(90^\circ\) (i.e. swap \(w\) and \(h\)).
Your task is to determine whether it is possible to place all \(n\) frames on the wall without overlapping. In other words, check if by placing the frames either in the normal orientation or rotated orientation, you can fit at least \(n\) frames on the wall.
Hint: The number of frames that can fit in an orientation is given by \(\left\lfloor\frac{W}{w}\right\rfloor \times \left\lfloor\frac{H}{h}\right\rfloor\) for the normal orientation and \(\left\lfloor\frac{W}{h}\right\rfloor \times \left\lfloor\frac{H}{w}\right\rfloor\) for the rotated orientation.
inputFormat
The input consists of a single line containing five integers: \(n\), \(W\), \(H\), \(w\), and \(h\), where:
- \(n\) is the number of frames to place.
- \(W\) and \(H\) are the width and height of the wall.
- \(w\) and \(h\) are the width and height of each frame.
All values are separated by spaces.
outputFormat
Output a single line: "YES" if it is possible to place all \(n\) frames on the wall without overlapping (possibly by rotating some frames), or "NO" otherwise.
## sample6 15 10 3 5
YES
</p>