Top Secret Task
Contest: Codeforces Round 327 (Div. 1)
Difficulty rating: 2300
Tags: dp

A top-secret military base under the command of Colonel Zuev is expecting an inspection from the Ministry of Defence. According to the charter, each top-secret military base must include a top-secret troop that should... well, we cannot tell you exactly what it should do, it is a top secret troop at the end. The problem is that Zuev's base is missing this top-secret troop for some reasons.

The colonel decided to deal with the problem immediately and ordered to line up in a single line all n soldiers of the base entrusted to him. Zuev knows that the loquacity of the i-th soldier from the left is equal to qi. Zuev wants to form the top-secret troop using k leftmost soldiers in the line, thus he wants their total loquacity to be as small as possible (as the troop should remain top-secret). To achieve this, he is going to choose a pair of consecutive soldiers and swap them. He intends to do so no more than s times. Note that any soldier can be a participant of such swaps for any number of times. The problem turned out to be unusual, and colonel Zuev asked you to help.

Determine, what is the minimum total loquacity of the first k soldiers in the line, that can be achieved by performing no more than s swaps of two consecutive soldiers.

Input format:
The first line of the input contains three positive integers n, k, s (1 ≤ k ≤ n ≤ 150, 1 ≤ s ≤ 109) — the number of soldiers in the line, the size of the top-secret troop to be formed and the maximum possible number of swap operations of the consecutive pair of soldiers, respectively.

The second line of the input contains n integer qi (1 ≤ qi ≤ 1 000 000) — the values of loquacity of soldiers in order they follow in line from left to right.

Output format:
Print a single integer — the minimum possible total loquacity of the top-secret troop.

Constraints:
Time limit: 3.0 s
Memory limit: 256.0 MB

Note:
In the first sample Colonel has to swap second and third soldiers, he doesn't really need the remaining swap. The resulting soldiers order is: (2, 1, 4). Minimum possible summary loquacity of the secret troop is 3. In the second sample Colonel will perform swaps in the following order:

1. (10, 1, 6 — 2, 5)
2. (10, 1, 2, 6 — 5)

The resulting soldiers order is (10, 1, 2, 5, 6).

Minimum possible summary loquacity is equal to 18.

Example input:
3 2 2
2 4 1

Example output:
3

Example input:
5 4 2
10 1 6 2 5

Example output:
18

Editorial:
Рассмотрим номера солдат, которые войдут в сверхсекретную роту, пусть i1 < i2 ...  < ik. Тогда за какое минимальное количество количество операций T можно их поставить на первые k мест? Очевидно T = (i1 - 1) + ... + (ik - k). В тоже время это равно $$T = \sum_{p=1}^{k} i_p$$ - $${ \frac { k \cdot ( k + 1 ) } { 2 } }$$. T ≤ S $$\text{The image appears to be blurred, but it seems to contain a mathematical expression or a symbol that is not clearly discernible due to the blurriness. If there was intended text or a specific formula, it would need to be re-rendered with clearer imagery.}$$ получаем, что $$\sum_{p=1}^{k} i_p$$  ≤  $${ \frac { k \cdot ( k + 1 ) } { 2 } } + S$$. Пусть $$M = \frac{k \cdot (k + 1)}{2} + S$$, сведем нашу задачу к задаче о рюкзаке, солдат i имеет вес i ценность солдата — qi. Нужно выбрать k солдат, суммарным весом не больше чем M, с минимально возможной суммарной стоимостью. Это мы умеем делать за $$O\left(n \cdot k \cdot \left(S + \frac{k \cdot (k+1)}{2}\right)\right)$$ динамикой d[i][j][p] — среди первых i взять j с суммарным весом не больше M. Ограничения по памяти не позволяют хранить ее целиком, но при каждом пересчете мы пользуемся предыдущими значениями с i = i - 1, поэтому будем хранить только два уровня динамики.