## DMOPC '15 Contest 1 P2 - Itami and Squad

View as PDF

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Itami has been chosen as one of officers to lead recon squads into an unknown land! To determine the members of each squad, the leaders will draft soldiers from a pool of soldiers of initial size .

Itami has designated a number for each soldier, representing the strength of the -th soldier in battle. Of course, he knows that every squad leader would like to have the strongest squad possible, and will therefore pick the best soldiers available to them (a soldier is considered to be better than another soldier if ). If there are multiple "best" soldiers, the squad leader will pick a random one — it doesn't matter exactly which one they choose.

Since the army is a well-structured organization, the order of drafting will be determined by seniority. Itami is ranked -th out of the squad leaders. In the drafting process, the most senior squad leader will pick a soldier, then the second in seniority will pick a soldier out of the remaining pool, and so on. If there are still soldiers remaining after the most junior squad leader has made his pick, the process will repeat until there are no more remaining.

The strength of a squad is defined as the sum of strengths of all its members. Itami would like to know what the strength of his squad would be, following this process.

#### Input Specification

The first line of input will contain , the number of soldiers, , the number of squad leaders and , Itami's rank amongst the squad leaders, each separated by one space.

The second line will contain space-separated integers, , denoting the strength of the -th soldier.

#### Output Specification

Output one integer, the strength of Itami's squad following the process described above.

#### Sample Input 1

5 2 2
2 7 1 4 3

#### Sample Output 1

6

#### Explanation for Sample Output 1

Itami has second pick in this case. Following the drafting process, his senior will pick the soldiers with strengths , , , and he will pick the soldiers with strengths and . Therefore the total strength of his squad will be .

#### Sample Input 2

3 4 4
1000 1000 1000

#### Sample Output 2

0

#### Explanation for Sample Output 2

Poor Itami! He doesn't even get to pick a single soldier since he is fourth pick and there are only 3 soldiers available. Now he'll be sulking in a corner, jealously looking at the other squads with their superhuman soldiers.

#### Sample Input 3

9 1 1
1 1 1 1 1 1 1 1 1

#### Sample Output 3

9

#### Explanation for Sample Output 3

• commented on Oct. 13, 2015, 7:18 p.m.

The way I answered this question was very simple, I tried to make it as efficient as I could, but it seems that my program always take more than 1 second to solve test case 6.

• commented on Oct. 13, 2015, 7:25 p.m.

I've reviewed the test case in question, and it fits within the given constraints. A Python solution exists that can run within the given time limit.

• commented on Oct. 13, 2015, 7:25 p.m.

When there's a whole page of other people getting 100/100 ACs, it's probably something wrong with your code, not the testcases.