#C11639. Total Width of Paintings
Total Width of Paintings
Total Width of Paintings
You are given a collection of paintings. Each painting has a height and a width. Your task is to determine the total width of all the paintings such that they do not exceed a given height restriction.
If any painting has a height that is greater than the restriction \(H\), then you should output \(-1\) immediately.
Note: All dimensions are given as positive integers.
inputFormat
The input is read from stdin and is formatted as follows:
- The first line contains two space-separated integers \(m\) and \(H\), where \(m\) is the number of paintings and \(H\) is the height restriction.
- The following \(m\) lines each contain two space-separated integers representing the height and width of a painting.
If \(m = 0\), there will be no additional lines after the first line.
outputFormat
Output a single integer to stdout:
- If any painting has a height greater than \(H\), output \(-1\).
- Otherwise, output the total sum of the widths of the paintings.
5 10
7 3
8 5
6 2
12 4
9 6
-1