#K39632. Missing Books Sum
Missing Books Sum
Missing Books Sum
You are given a collection of books with unique IDs. The total number of books in the collection is M, and the sum of the IDs of all these books is given as S. However, you only possess N books whose IDs are provided in the input. The goal is to determine the sum of the IDs of the missing books.
You can compute the sum of the missing books' IDs as \( S - \sum_{i=1}^{N} a_i \), where \(a_i\) represents the given book IDs. Note that the number of missing books is \( M - N \). If no books are missing (i.e. \(M = N\)) or if the sum of the provided book IDs exceeds \(S\), then the answer should be \(-1\).
inputFormat
The first line of the input contains a single integer T
representing the number of test cases.
For each test case, there are two lines:
- The first line contains three space-separated integers:
N
(the number of books you have),M
(the total number of books), andS
(the sum of the IDs of all M books). - The second line contains
N
space-separated integers representing the IDs of the available books.
outputFormat
For each test case, output a single line that contains one integer: the sum of the missing books' IDs. If the condition is not met (i.e. when M = N
or the sum of the provided book IDs exceeds S
), output -1
.
3
3 5 100
10 20 30
2 4 50
5 10
4 5 120
15 25 35 40
40
35
5
</p>