#C10965. Book Allocation Problem

    ID: 40228 Type: Default 1000ms 256MiB

Book Allocation Problem

Book Allocation Problem

You are given n books and k students. Each book has a certain number of pages. The books are arranged in a fixed order and every student must be assigned a contiguous block of books.

Your task is to allocate the books to the students such that the maximum number of pages assigned to any student is minimized. Formally, if the allocation results in students receiving p1, p2, ..., pk pages respectively, you need to minimize max(p1, p2, ..., pk).

This can be mathematically formulated as finding the minimum maxPages such that:

maxi=1k(pi)maxPages\max_{i=1}^k (p_i) \leq maxPages

If the number of books n is less than the number of students k, the task is impossible and you must output -1.

inputFormat

The first line of input contains two space-separated integers n and k, where:

  • n is the number of books.
  • k is the number of students.

The second line contains n space-separated integers, representing the number of pages in each book in the given order.

outputFormat

Output a single integer representing the minimized maximum number of pages allocated to any student. If it is not possible to allocate the books (i.e. when n < k), output -1.

## sample
4 2
12 34 67 90
113

</p>