Booklets

Time limit1sMemory limit128 MB

Summary
Given booklets sorted by page count split among schools using floor/ceiling division with a strict serving order, find the first booklet's page count given to a specified school.
Level

Medium4 of 10

Topics
Sorting, Math, Implementation
Solved
No attempts yet

Problem

Bob must distribute advertising booklets for extra-curricular activities to several schools. The booklets have different numbers of pages. Given the page count of every booklet and the number of schools, Bob hands them out so that each school receives either the lower integer part (LIP) or the upper integer part (UIP) of (number of booklets) / (number of schools) — that is, ⌊B/S⌋\lfloor B / S \rfloor or ⌈B/S⌉\lceil B / S \rceil booklets, where BB is the number of booklets and SS is the number of schools.

Bob must also obey these rules:

  • He serves all the schools that receive the UIP count of booklets first, and only then the schools that receive the LIP count.
  • If a school SiS_i is served before a school SjS_j (that is, i<ji < j), then every booklet given to SiS_i has no more pages than any booklet given to SjS_j. Equivalently, across schools the booklets are handed out in non-decreasing order of pages.
  • The booklets given to a single school are handed out in the same relative order in which they appear on Bob's list.

Back at the company, Bob's boss asks for the number of pages of the first booklet distributed to a particular school, where schools are numbered from 00 in the order Bob served them. Compute that number.

Input

The input contains several data sets; read them until the end of the file. Each data set gives, in order: the number of schools, the index of the school specified by the boss (numbered from 00), the number of booklets (fewer than 30003000), and then the number of pages of each booklet (each value fits in an integer). Whitespace may appear freely between the numbers. The input is always valid.

Output

For each data set, print on its own line the number of pages of the first booklet distributed to the specified school.

Examples1

  1. Example 1

    Input
    3
    2
    7
    3 5 9 1 11 14 2
    
    Expected output
    11