#C3334. Overflow Water Calculation

    ID: 46750 Type: Default 1000ms 256MiB

Overflow Water Calculation

Overflow Water Calculation

You are given several water tanks with specified capacities. After a heavy rain session, the total collected water \(R\) may exceed the combined capacity of all tanks. The water that cannot be stored in the tanks overflows. Your task is to compute the amount of overflow water for each test case.

For each test case, you will be provided with:

  • An integer \(N\) which denotes the number of tanks.
  • A list of \(N\) integers representing the capacities of the tanks.
  • An integer \(R\) representing the total collected rainwater.

The overflow water is calculated as:

[ \text{overflow} = \max\left(0, R - \sum_{i=1}^{N} capacity_i\right). ]

Print the overflow amount for each test case on a new line.

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains an integer \(T\), the number of test cases.
  2. For each test case, the following three lines are provided:
    1. An integer \(N\) representing the number of tanks.
    2. A line with \(N\) space-separated integers representing the capacities of each tank.
    3. An integer \(R\) representing the total collected rainwater.

outputFormat

For each test case, output a single integer representing the amount of overflow water. Each answer should be printed on a new line to standard output (stdout).

## sample
1
3
100 200 300
600
0

</p>