Types of burgers

4.2

5 votes
Greedy Algorithms, Algorithms, Basics of Greedy Algorithms, Greedy algorithm
Problem

Bob sells burgers with three different combinations, B1, B2 and B3. There are total X, Y, and Z burgers with combinations, B1, B2, and B3 respectively. Each burger has an integer value called deliciousness as follows:

  • The deliciousness of the burgers with the B1 combination are B11,B12,B13,....,B1X.
  • The deliciousness of the burgers with the B2 combination are B21,B22,B23,....,B2Y.
  • The deliciousness of the burgers with the B3 combination are B31,B32,B33,....,B3Z.

Alice decides to buy K boxes containing three burgers, one from each of the combinations. The deliciousness of a box is the sum of the deliciousness of the burgers present inside it. 

There are XYZ such ways to select a box. Print the maximum total sum of deliciousness that Alice can get by buying K boxes.

Input format

  • The first line contains an integer T denoting the number of test cases.
  • The first line of each test case contains three space-separated integers X, Y, and Z.
  • The second line of each test case contains a single integer K.
  • The third line of each test case contains X space-separated integers denoting array B1i.
  • The fourth line of each test case contains Y space-separated integers denoting array B2j.
  • The fifth line of each test case contains Z space-separated integers denoting array B3k.

Output format

For each test case, print the maximum total sum of deliciousness that Alice can get by buying K boxes in a new line.

Constraints

1T101X,Y,Z10001Kmin(3000,XYZ)1B1i,B2j,B3k1000000000

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For the first testcase, the combinations of burger in the boxes are (B11,B21,B32),(B11,B22,B31),(B11,B22,B32),(B12,B21,B31),(B12,B21,B32),(B12,B22,B31) and (B12,B22,B32). Thus, the total sum of deliciousness Alice can buy is 100.

Editor Image

?