
1. Start printing the pages of a comic book in an unoccupied ‘ith’ printing machine.
2. After ‘printMachine[i]' minutes, the printed pages are taken from the ‘ith’ printing machine.
3. After a non-negative amount of time, the printed pages of the comic book are placed in an unoccupied binding machine.
4. After ‘K’ minutes, the pages are removed from the binding machine.
X=3, Y=2, Z=2, K=5
printMachine = [5, 7]
We can print the first book in the first printing machine at ‘T=0’, which takes five minutes. After that, we can give it to the first binding machine, which will bind it till ‘T=10’.
Similarly, we can print the second book in the second printing machine at ‘T=0’, which takes seven minutes. After that, we can give it to the second binding machine, which will bind it till ‘T=12’.
Hence, will finish both books in 12 minutes. So, the answer to this example will be 12.
First-line contains 'T,' denoting the number of Test cases.
For each Test case:
The first line contains four integers ‘X’,’ Y’,’ Z’, and ‘K’
The second line contains ‘Y’ integers, the value for the ‘printMachine’ array.
For each test case, print a single integer denoting the time taken to print all the books.
Print the output of each test case in a new line.
1 <= T <= 10
1 <= X <= 10^6
1 <= Y <= 10^5
1 <= Z <= 10^9
1 <= K <= 10^9
1 <= printMachine[i] <= 10^9
Time Limit: 1 sec
printingEndAt = printingMachine.first
timeToPrint = printingMachine.second
bindingStartAt = max(printingEndAt, bindingMachine)
bindingEndAt = bindingStartAt + K