#P12258. Backpack Weight Selection

    ID: 14365 Type: Default 1000ms 256MiB

Backpack Weight Selection

Backpack Weight Selection

In a magical shop, there are \(N\) different items. The weight of the \(i\)-th item is \(W_i\). There are infinitely many copies of each item. The shop owner may choose any combination of items (each item available in infinite quantity) and pack them into a bag. The weight of a bag is defined as the sum of the weights of the items inside.

Little Blue wants his bag to contain at least \(K\) items. Among all possible bags satisfying this requirement, consider the set of distinct weights. After sorting these weights in increasing order, determine the weight that ranks \(L\)-th.

Input Constraints: It is guaranteed that a solution exists under the given constraints.

inputFormat

The first line contains three integers \(N\), \(K\), and \(L\) separated by spaces.

The second line contains \(N\) integers \(W_1, W_2, \dots, W_N\) representing the weight of each item.

outputFormat

Output a single integer: the \(L\)-th smallest distinct bag weight that can be formed using at least \(K\) items.

sample

2 2 3
1 2
4