[The problem appeared in TopCoder SRM 592 (Div-2, Level-1)]

**Problem link:** http://community.topcoder.com/stat?c=problem_statement&pm=12112

**Problem Statement:**

Little Elephant from the Zoo of Lviv has a bunch of books. You are given a int[] pages. Each element of pages is the number of pages in one of those books. There are no two books with the same number of pages.

You are also given a int number. As a homework from the teacher, Little Elephant must read exactly number of his books during the summer. (Little Elephant has strictly more than number books.)

All other elephants in the school also got the exact same homework. Little Elephant knows that the other elephants are lazy: they will simply pick the shortest number books, so that they have to read the smallest possible total number of pages. Little Elephant wants to be a good student and read a bit more than the other elephants. He wants to pick the subset of books with the second smallest number of pages. In other words, he wants to pick a subset of books with the following properties:

1. There are exactly number books in the chosen subset.

2. The total number of pages of those books is greater than the smallest possible total number of pages.

3. The total number of pages of those books is as small as possible (given the above conditions).

Return the total number of pages Little Elephant will have to read.

Continue reading

## Recent Comments