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.
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 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
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
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
Explanation for Sample Output 3
Itami is the only squad leader! Now he has a large squad full of inexperienced soldiers.
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.
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.
When there's a whole page of other people getting 100/100 ACs, it's probably something wrong with your code, not the testcases.