This page is still under construction.

Parts of this page are still being built. What you see may change.

Klocki

Time limit1sMemory limit512 MB

Summary
Choose at most k of the n blocks so their total mass is as large as possible without exceeding s.
Level

Medium6 of 10

Topics
Divide and conquer, Sorting, Binary search
Solved
No attempts yet

Problem

Bajtek has a great many blocks, and he loves playing with them. Unfortunately he has only one box for them, and it is so small that not all of the blocks fit inside.

Bajtek is a very tidy boy and does not like leaving a mess in his room, so after playing he always packs the blocks into the box and puts the box on a shelf.

All blocks are the same size, so no matter which ones he picks he can fit at most kk blocks into the box. As far as possible he would like to leave only the light blocks on the floor, so he always tries to pack the heavier ones. Sometimes, though, the box turns out to be too heavy for him to lift onto the shelf, because Bajtek is only a little boy. He therefore tries to pack the blocks so that their total mass is as large as possible while still being light enough for him to lift.

Bajtek is tired of repacking the blocks just because he is not strong enough to lift the box. Write a program that tells him how to pack the blocks optimally.

Input

The first line contains three integers nn, kk, and ss (k≤n≤30k \le n \le 30, 1≤k≤121 \le k \le 12, 1≤s≤1061 \le s \le 10^6), separated by single spaces. They denote the total number of blocks, the maximum number of blocks that fit in the box, and Bajtek's strength (the maximum mass of a box he can lift), respectively.

The second line contains nn integers mim_i (1≤mi≤1061 \le m_i \le 10^6), separated by single spaces, denoting the masses of the individual blocks.

The mass of the box itself is ignored (you may assume it is 00).

Output

Print a single integer MM: the maximum mass of a box loaded with blocks that Bajtek can lift.

Hint

An empty box has mass 00, which Bajtek can always lift, so the answer is never less than 00. For example, when s=5s = 5, at most 22 blocks may be packed, and the block masses are 1,3,61, 3, 6, the best choice is to pack the blocks of mass 11 and 33 for a total of 44. The block of mass 66 already exceeds 55 on its own, and combinations such as 1+61+6 or 3+63+6 also exceed 55.

Examples3

  1. Example 1

    Input
    3 2 5
    1 3 6
    
    Expected output
    4
    
  2. Example 2

    Input
    3 2 5
    6 7 8
    
    Expected output
    0
    
  3. Example 3

    Input
    5 3 10
    2 3 5 8 9
    
    Expected output
    10