#C7958. Minimum Wall Width Calculation
Minimum Wall Width Calculation
Minimum Wall Width Calculation
You are given n paintings, each with a height and width. You also have a wall of a fixed height H. Your task is to determine the minimum possible total width of the wall such that all paintings can be placed side by side. For each painting, if its height is less than or equal to H, it is placed in its original orientation and contributes its width to the total. If its height is greater than H, the painting must be rotated 90° so that its original height now contributes as the width.
The effective width of a painting is given by: \[ w_{effective} = \begin{cases} w, & \text{if } h \leq H, \\ h, & \text{otherwise.} \end{cases} \]
The answer is the sum of the effective widths of all paintings.
inputFormat
The input is given via standard input (stdin) in the following format:
n h1 w1 h2 w2 ... hn wn H
where:
n
is the number of paintings.- Each of the next
n
lines contains two integershi
andwi
representing the height and width of the i-th painting. H
is the fixed height of the wall.
outputFormat
Output a single integer to standard output (stdout) representing the minimum total width of the wall required.
## sample2
40 30
60 20
60
50
</p>