#P11552. Max Protective Layer for Mars Research Base
Max Protective Layer for Mars Research Base
Max Protective Layer for Mars Research Base
In order to develop Mars, a research base must be constructed. The base consists of n identical rectangular modules. Each module is a habitation unit of size \(a \times b\).
To improve the reliability of the modules, engineers can add an extra protective layer around each module. The protective layer has an integer thickness \(d\); with the layer, the overall dimensions of a module become \((a + 2d) \times (b + 2d)\).
All modules must be placed within a predefined rectangular area of size \(w \times h\). The sides of each module must be parallel to the sides of the area, and all modules must have the same orientation (i.e. either all modules are placed as \((a+2d, b+2d)\) or all are rotated to \((b+2d, a+2d)\)). Determine the maximum integer \(d\) so that at least \(n\) modules can be arranged inside the area.
inputFormat
The input consists of a single line containing five space-separated integers: \(n\), \(a\), \(b\), \(w\), and \(h\).
outputFormat
Output a single integer representing the maximum protective layer thickness \(d\) that can be applied so that all \(n\) modules fit within the area.
sample
1 2 3 6 7
2