#C11104. Minimum Extra Spending
Minimum Extra Spending
Minimum Extra Spending
You are given a list of prices of items and a spending threshold. Calculate the minimum extra amount needed to reach the threshold.
Let \(S\) be the sum of the prices, i.e., \(S = \sum_{i=1}^n p_i\). If \(S \geq T\) where \(T\) is the threshold, then the answer is 0. Otherwise, output \(T - S\).
For example, if the prices are [150, 300, 600, 900, 1200] and the threshold is 5000, then \(S = 3150\) and the answer is \(5000 - 3150 = 1850\).
inputFormat
The input is read from stdin and has the following format:
- The first line contains a single integer \(n\) representing the number of items.
- The second line contains \(n\) space-separated integers representing the prices of the items. (If \(n=0\), this line may be empty.)
- The third line contains a single integer \(T\) representing the spending threshold.
outputFormat
Print a single integer to stdout which is the minimum extra amount needed so that the total spending is at least the threshold. If the total spending is already at or above the threshold, print 0.
## sample5
150 300 600 900 1200
5000
1850