Company: Nutanix
Difficulty: hard
# Comics Debacle Marvel must publish `X` comic books. There are `Y` printing machines and `Z` identical binding machines. Printing machine `i` takes `P[i]` minutes to print one complete book. Every binding machine takes `K` minutes to bind one printed book. A machine can process at most one book at a time. A book must finish printing before it can begin binding, but it may wait between the two stages. Loading and unloading take no time. Find the minimum time needed to finish all `X` books. ## Input Format - The first line contains `T`, the number of test cases. - For each test case: - One line contains `X Y Z K`. - The next line contains `Y` integers `P[1] ... P[Y]`. ## Output Format For each test case, print the minimum completion time on its own line. ## Constraints - `1 <= T <= 10` - `1 <= X <= 1000000` - `1 <= Y <= 100000` - `1 <= Z <= 1000000000` - `1 <= K, P[i] <= 1000000000` - Use 64-bit arithmetic. ## Example Input: 3 2 1 1 34 1100 2 3 2 10 10 16 1