#C9982. Maximum Contiguous Books Shelf
Maximum Contiguous Books Shelf
Maximum Contiguous Books Shelf
You are given a sequence of n
books with the number of pages in each book provided in an array pages
and a positive integer k
. Your task is to determine the maximum number of contiguous books that Peter can place on a shelf such that the sum of their pages is divisible by k
. More formally, find the maximum length L for which there exists indices i and j (with 0 ≤ i ≤ j < n) satisfying:
If no such contiguous segment exists, output 0.
inputFormat
The first line of input contains two space-separated integers n
and k
, where n
is the number of books and k
is the divisor.
The second line contains n
space-separated integers representing the number of pages in each book.
outputFormat
Output a single integer, the maximum number of contiguous books such that the sum of their pages is divisible by k
.
5 3
4 3 6 3 4
3
</p>