Mithai

0

0 votes
Hard
Problem

Ser has recently set up many sweet factories and is all set to give many big businessmen a run for their money. On one of his regular inspection days, he visits a factory and finds N different types of sweets prepared on that day. Each sweet has a taste value Ti. Ser asks his workers to prepare boxes of sweets, with each box containing a non-empty subset of sweets. The taste of each box is the sum of taste values of all sweets in that box.

Now, Ser asks his workers to stack up all boxes (there will be 2N1 such boxes) from top to bottom in non-decreasing order of their tastes (i.e the box with maximum taste will be at the bottom). Suddenly, Ser's brother whom he fondly calls Big-B walks in and asks him how tasty is the Kth box from the the top. Help Sir impress Big-B.

Input Format

The first line contains a number N denoting the number of different sweets.
Next line contains N space separated positive integers wherein the i'th integer represents Ti.
Next line contains K.

Output Format

Print a single integer, the taste of the Kth box from the top.

Constraints

1<=N<=30

1<=Ti<=109

1<=K<=(2N1)

Subtask 1 (10 points): N<=20

Subtask 2 (20 points): N<=30 , Ti<=104

Subtask 3 (70 points): Original constraints

Sample Input
3
1 3 4
4
Sample Output
4
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

All the sweet boxes arranged from top to bottom in non-decreasing order of their tastes are as follows:

1, 3, 4, 4, 5, 7, 8

Hence, the 4th box from the top has a taste of 4.

Editor Image

?