-->
当前位置:首页 > 题库

PROGRAMMING:Bookshelf (Cixi primary school, 2012)

Luz5年前 (2021-05-10)题库498
In order to facilitate students to access information, the tutor of the program design interest group plans to put n books that have been accumulated for many years on the bookshelf of the classroom.
The bookshelves in the classroom are stacked one by one, and each floor can hold up to m books. The height of each layer is determined by the highest book in the layer. If the book is not placed, the height of this layer is considered to be 0. In order to make it easy for each student to get the books they want, the total height of the bookshelf should be as low as possible. Please program to calculate the minimum total height of the bookshelf when the n books are placed on the bookshelf. The thickness of the book and the material of the bookshelf are not considered in the calculation process.
###Input format:
Enter a total of N + 1 lines.
The first line contains two integers n and m (1 ≤ m ≤ n ≤ 100000).
Next, N lines, 1 positive integer for each line, respectively representing the height of each book (the height of each book does not exceed 100).
###Output format:
Output a total of 1 line, indicating the minimum total height of the bookshelf after n books are put into the bookshelf.
###Input example:
```in
3 2
twenty
ten
thirty
```
###Output example:
```out
forty
```
[example explanation]
If two books with height of 30 and 20 are placed on one floor, the height of this floor is 30; if the book with height of 10 is placed on another floor, the height of this floor is 10, and the total height of the bookshelf is 40, which meets the minimum requirement.
[data range agreement]
The height of each book is a positive integer of no more than 100.
For 70% of the data, 1 ≤ m ≤ n ≤ 1000.
For 100% data, 1 ≤ m ≤ n ≤ 100000.







answer:If there is no answer, please comment