Types of burgers
Practice
4.2 (5 votes)
Greedy algorithms
Algorithms
Basics of greedy algorithms
Greedy algorithm
Problem
82% Success 1559 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

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

  • The deliciousness of the burgers with the $$B_1$$ combination are \(B_{11}, B_{12}, B_{13}, .... , B_{1X}\).
  • The deliciousness of the burgers with the $$B_2$$ combination are \(B_{21}, B_{22}, B_{23}, .... , B_{2Y}\).
  • The deliciousness of the burgers with the $$B_3$$ combination are \(B_{31}, B_{32}, B_{33}, .... , B_{3Z}\).

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 \(X*Y*Z\) 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 $$B_{1i}$$.
  • The fourth line of each test case contains $$Y$$ space-separated integers denoting array $$B_{2j}$$.
  • The fifth line of each test case contains $$Z$$ space-separated integers denoting array $$B_{3k}$$.

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

\(1 \le T \le 10\\ 1 \le X,Y,Z \le 1000\\ 1 \le K \le min(3000,X*Y*Z)\\ 1 \le B_{1i},B_{2j},B_{3k} \le 1000000000\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
1 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Points:30
9 votes
Tags:
AlgorithmsGreedy AlgorithmsHiringImplementationMedium
Points:30
9 votes
Tags:
DatastructuresGreedy AlgorithmsBasics of Greedy AlgorithmsAlgorithms