cswork / OAOpen practice workspace

SnowflakeOA #10

Team Formation — Alternating Front / Back Selection

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & Heaps

In each round, pick the highest-scoring person from the union of the first k and the last k people in the remaining list, breaking ties by the smallest index; remove that person and continue until t people have been chosen. Find the sum of their scores. The original title's alternating between the two ends does not match the body text; the body text takes precedence.

Input

The first line contains n t k, and the second line contains n scores. This site sets 1≤t,k≤n≤100000 and 1≤score≤10⁹.

Output

Output the single integer required by the problem.

Example 1

Input:

5 2 1
5 1 9 2 4

Output:

9

Example 2

Input:

4 2 1
5 100 1 5

Output:

105

Example 3

Input:

3 3 2
1 2 3

Output:

6

Example notes

The answers to the three public examples are, in order: 9; 105; 6. All examples have been verified by independent small-scale enumeration or state search.

Editorial

Loading solution…