#C8902. Widget Packing Validation
Widget Packing Validation
Widget Packing Validation
You are given a collection of widgets and a box. Each widget has a width, height, and weight. The box has dimensions given by its width, height, and depth. In addition, there is a maximum weight capacity for the box.
Your task is to determine if all the widgets can be fit into the box under the following conditions:
- The total weight of the widgets must not exceed the maximum weight.
- The widgets, when arranged side by side, have a combined width equal to the sum of all their widths and a combined height equal to the sum of all their heights. Using these, we calculate a combined volume as $$\text{combinedVolume} = \left(\sum_{i=1}^{n}width_i\right) \times \left(\sum_{i=1}^{n}height_i\right) \times depth_{box}.$$ This combined volume must not exceed the box's volume which is $$\text{boxVolume} = width_{box} \times height_{box} \times depth_{box}.$$
If both conditions are satisfied, the widgets can be successfully packed into the box; otherwise, they cannot.
inputFormat
The input is given via stdin in the following format:
- An integer n representing the number of widgets.
- Next, n lines follow; each contains three space-separated integers representing the
width
,height
, andweight
of a widget. - A line with three space-separated integers representing the box's
width
,height
, anddepth
. - A single integer representing
maxWeight
, the maximum weight the box can handle.
outputFormat
Output a single line to stdout containing either True
if the widgets can fit in the box, or False
if they cannot.
2
2 3 4
2 3 4
5 10 3
15
True